Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Sep 2012 01:39:26 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241019 - head/usr.sbin/bsdconfig/share
Message-ID:  <201209280139.q8S1dQ7h045371@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Fri Sep 28 01:39:25 2012
New Revision: 241019
URL: http://svn.freebsd.org/changeset/base/241019

Log:
  Sanitize varname argument in f_sysrc_find. This is as much for security as it
  is for sanity.
  
  Reviewed by:	jilles
  Approved by:	adrian (co-mentor)

Modified:
  head/usr.sbin/bsdconfig/share/sysrc.subr

Modified: head/usr.sbin/bsdconfig/share/sysrc.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/sysrc.subr	Fri Sep 28 01:04:10 2012	(r241018)
+++ head/usr.sbin/bsdconfig/share/sysrc.subr	Fri Sep 28 01:39:25 2012	(r241019)
@@ -49,6 +49,17 @@ f_include_lang $BSDCFG_LIBE/include/mess
 SUCCESS=0
 FAILURE=1
 
+#
+# Valid characters that can appear in an sh(1) variable name
+#
+# Please note that the character ranges A-Z and a-z should be avoided because
+# these can include accent characters (which are not valid in a variable name).
+# For example, A-Z matches any character that sorts after A but before Z,
+# including A and Z. Although ASCII order would make more sense, that is not
+# how it works.
+#
+VALID_VARNAME_CHARS="0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
+
 ############################################################ FUNCTIONS
 
 # f_clean_env [ --except $varname ... ]
@@ -243,14 +254,16 @@ f_sysrc_get_default()
 #
 f_sysrc_find()
 {
-	local varname="$1"
+	local varname="${1%%[!$VALID_VARNAME_CHARS]*}"
 	local regex="^[[:space:]]*$varname="
 	local rc_conf_files="$( f_sysrc_get rc_conf_files )"
 	local conf_files=
 	local file
 
 	# Check parameters
-	[ "$varname" ] || return $FAILURE
+	case "$varname" in
+	""|[0-9]*) return $FAILURE
+	esac
 
 	#
 	# If RC_CONFS is defined, set $rc_conf_files to an explicit



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209280139.q8S1dQ7h045371>