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
This commit is contained in:
Colin Walters 2013-09-01 04:16:52 -04:00
parent 52dd6b0b74
commit 9e497a4ce7
1 changed files with 7 additions and 0 deletions

View File

@ -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';