diff options
author | Thomas Bächler <thomas@archlinux.org> | 2011-04-14 22:38:14 +0200 |
---|---|---|
committer | Thomas Bächler <thomas@archlinux.org> | 2011-04-14 23:22:10 +0200 |
commit | 01b2f556af1a93dcf9c79f8cbfeabfc5fced8a68 (patch) | |
tree | c8213464d2ccddadeacd7cbe2a01642677e11687 /init_functions | |
parent | 8c59faaf8e8d159854426cba144f0c8512f2ca5c (diff) | |
download | mkinitcpio-01b2f556af1a93dcf9c79f8cbfeabfc5fced8a68.tar.gz mkinitcpio-01b2f556af1a93dcf9c79f8cbfeabfc5fced8a68.tar.xz |
Rewrite parse_cmdline (again)
This should properly handle all ugly characters in values,
omit settings any forbidden variable names and take care
of double-quoted values with spaces in them.
This should finally fix FS#23467, FS#22080 and FS#13900.
Diffstat (limited to 'init_functions')
-rw-r--r-- | init_functions | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/init_functions b/init_functions index fd5bbb6..be3599e 100644 --- a/init_functions +++ b/init_functions @@ -31,27 +31,44 @@ launch_interactive_shell() { } parse_cmdline() { - eval set -- $(cat /proc/cmdline) - for cmd in "$@"; do - case "${cmd}" in - \#*) break ;; # ignore everything after a # in the commandline - # The kernel passes those to the kernel on its own - [0123456Ss]) ;; - [0-9]*) ;; - single) ;; - rw) readwrite="yes" ;; - ro) readwrite="no" ;; - # only export stuff that does work with ash :) - *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)" - cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|\.|_|g')" - cmd="$(echo "${cmd}" | sed 's|-|_|g')=\"${rhs}\"" - (echo "${cmd}" | grep -qe '^[0-9]') || eval "${cmd}" - ;; - *) cmd="$(echo "${cmd}" | sed 's|\.|_|g')" - cmd="$(echo "${cmd}" | sed 's|-|_|g')" - (echo "${cmd}" | grep -qe '^[0-9]') || eval "${cmd}=y" - ;; - esac + 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) readwrite="yes" ;; + ro) readwrite="no" ;; + # only export stuff that does work with ash :) + *=*) rhs="$(echo "${w}" | cut -d= -f2-)" + lhs="$(echo "${w}" | cut -d= -f1 | sed 's|\.|_|g;s|-|_|g;')" + if [ "${rhs:0:1}" = "\"" ]; then + if [ "${rhs:$((${#rhs}-1))}" = "\"" ]; then + rhs="${rhs:1:$((${#rhs}-2))}" + else + rhs="${rhs:1}" + in_quotes=1 + continue + fi + fi + (echo "${lhs}" | grep -qe '^[0-9]' -e '[^a-zA-Z0-9_]') || eval ${lhs}=\${rhs} + ;; + *) lhs="$(echo "${w}" | sed 's|\.|_|g;s|-|_|g;')" + (echo "${lhs}" | grep -qe '^[0-9]' -e '[^a-zA-Z0-9_]') || eval ${lhs}=y + ;; + esac + else + if [ "${w:$((${#w}-1))}" = "\"" ]; then + rhs="${rhs} ${w:0:$((${#w}-1))}" + in_quotes=0 + (echo "${lhs}" | grep -qe '^[0-9]' -e '[^a-zA-Z0-9_]') || eval ${lhs}=\${rhs} + else + rhs="${rhs} ${w}" + fi + fi done } |