From owner-svn-src-head@FreeBSD.ORG Fri Sep 28 01:39:26 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8E5341065670; Fri, 28 Sep 2012 01:39:26 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 795FE8FC0A; Fri, 28 Sep 2012 01:39:26 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q8S1dQaf045374; Fri, 28 Sep 2012 01:39:26 GMT (envelope-from dteske@svn.freebsd.org) Received: (from dteske@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q8S1dQ7h045371; Fri, 28 Sep 2012 01:39:26 GMT (envelope-from dteske@svn.freebsd.org) Message-Id: <201209280139.q8S1dQ7h045371@svn.freebsd.org> From: Devin Teske Date: Fri, 28 Sep 2012 01:39:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r241019 - head/usr.sbin/bsdconfig/share X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Sep 2012 01:39:26 -0000 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