Skip to content

Commit

Permalink
Fix problems in parsing the kernel command line
Browse files Browse the repository at this point in the history
The kernel command line allows quoted strings with whitespace in them. Until now,
such parameters would crash /init and cause a kernel panic.
Move parsing into a function and use the 'set' builtin to split /proc/cmdline
into arguments.

Fixes FS#13900 and FS#22080.
  • Loading branch information
brain0 committed Apr 10, 2011
1 parent 9fcd9c1 commit d1264eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
25 changes: 2 additions & 23 deletions init
Expand Up @@ -19,36 +19,15 @@ else
fi
/bin/mount -t tmpfs run /run -o nosuid,noexec,nodev,mode=1777,size=10M

read CMDLINE </proc/cmdline

root=""
init=""
echo "/sbin/modprobe" > /proc/sys/kernel/modprobe

# set default mount handler
mount_handler="default_mount_handler"

for cmd in ${CMDLINE}; 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
done
# parse the kernel command line
parse_cmdline

# if available, start udevd at this stage
if [ -x /sbin/udevd ]; then
Expand Down
25 changes: 25 additions & 0 deletions init_functions
Expand Up @@ -30,6 +30,31 @@ launch_interactive_shell() {
/bin/sh -i
}

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
done
}

default_mount_handler() {
if [ ${root:0:5} != "/dev/" ] || ! poll_device "${root}" ${rootdelay}; then
msg "Root device '${root}' doesn't exist. Attempting to create it."
Expand Down

0 comments on commit d1264eb

Please sign in to comment.