From 9e497a4ce7cfde5db9605353590c1fe037f969ac Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 1 Sep 2013 04:16:52 -0400 Subject: [PATCH] prepare-root: Fix ostree= kernel argument at end Extracting the code for parse_ostree_cmdline() and running it on some test input (on RHEL6.4 glibc), I can reproduce the odd behavior from getline() where it apparently returns the size of the default malloc buffer in the size output, and some non-zero value. This behavior would be OK except that it breaks the logic for stripping off the trailing newline, which in turn breaks booting because we return "ostree=foo\n". This has worked so far in gnome-ostree because syslinux apparently injects initrd=/path/to/initrd as a final kernel argment. Anyways, we don't handle NUL characters here in /proc/cmdline, so let's just call strlen () to be safe. https://bugzilla.gnome.org/show_bug.cgi?id=707192 --- src/switchroot/ostree-prepare-root.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index a77da7c6..25ac66b4 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -54,8 +54,15 @@ parse_ostree_cmdline (void) if (!f) return NULL; + /* Note that /proc/cmdline will not end in a newline, so getline + * will fail unelss we provide a length. + */ if (getline (&cmdline, &len, f) < 0) return NULL; + /* ... but the length will be the size of the malloc buffer, not + * strlen(). Fix that. + */ + len = strlen (cmdline); if (cmdline[len-1] == '\n') cmdline[len-1] = '\0';