From 254c99b80f7f5269409b6af61cb90363bd9f66f5 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 13 Nov 2011 14:48:31 -0500 Subject: init_functions: simplify parse_cmdline Do variable name validation via the case labels rather than via PEs. This frees up the fallthrough case to simply ignore things we don't understand (and not exist). Signed-off-by: Dave Reisner --- init_functions | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'init_functions') diff --git a/init_functions b/init_functions index 5ec199e..42e6249 100644 --- a/init_functions +++ b/init_functions @@ -48,43 +48,41 @@ parse_cmdline() { local w in_quotes lhs rhs in_quotes=0 for w in $(cat /proc/cmdline); do - if [ ${in_quotes} -eq 0 ]; then - case "${w}" in - \#*) break ;; # ignore everything after a # in the commandline - # The kernel passes those to init on its own - [0123456Ss]) ;; - single) ;; - rw|ro) rwopt="$w" ;; - # only export stuff that does work with ash :) - =*) ;; - *=*) rhs=${w#*=} + if [ "$in_quotes" = 0 ]; then + case "$w" in + # ignore everything after a # in the commandline + \#*) break ;; + # special cases + rw|ro) rwopt=$w ;; + forcefsck) FORCEFSCK=-f ;; + # abide by shell variable naming rules + [[:alpha:]_]*=*) + rhs=${w#*=} lhs=${w%%=*} lhs=${lhs//[-.]/_} if [ '"' = "${rhs:0:1}" ]; then - if [ "${rhs:$((${#rhs}-1))}" = '"' ]; then + if [ '"' = "${rhs:$((${#rhs}-1))}" ]; then rhs="${rhs:1:$((${#rhs}-2))}" else - rhs="${rhs:1}" + rhs=${rhs:1} in_quotes=1 continue fi fi - [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=\${rhs} + eval $lhs=\$rhs ;; - forcefsck) - FORCEFSCK="-f" - ;; - *) lhs=${w//[-.]/_} - [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=y + [[:alpha:]_]*) + lhs=${w//[-.]/_} + eval $lhs=y ;; esac else if [ '"' = "${w:$((${#w}-1))}" ]; then - rhs="${rhs} ${w%\"}" + rhs="$rhs ${w%\"}" in_quotes=0 - [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=\${rhs} + eval $lhs=\$rhs else - rhs="${rhs} ${w}" + rhs="$rhs $w" fi fi done -- cgit v1.2.3-24-g4f1b