From 9edd7be26aef4fe4293835bb9dce3f49e7aff007 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 12 Nov 2011 23:14:51 +0100 Subject: [PATCH] Fix spaces handling in proc/self/mountinfo. * util/getroot.c (unescape): New function. (grub_find_root_device_from_mountinfo): Use unescape. --- ChangeLog | 7 +++++++ util/getroot.c | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/ChangeLog b/ChangeLog index c12f19951..ab253ddfd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-11-12 Vladimir Serbinenko + + Fix spaces handling in proc/self/mountinfo. + + * util/getroot.c (unescape): New function. + (grub_find_root_device_from_mountinfo): Use unescape. + 2011-11-12 Vladimir Serbinenko Support ZFS embedding. diff --git a/util/getroot.c b/util/getroot.c index f5d6d3f62..96879f545 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -129,6 +129,27 @@ struct mountinfo_entry can't deal with the multiple-device case yet, but in the meantime, we can at least cope with the single-device case by scanning /proc/self/mountinfo. */ +static void +unescape (char *str) +{ + char *optr; + const char *iptr; + for (iptr = optr = str; *iptr; optr++) + { + if (iptr[0] == '\\' && iptr[1] >= '0' && iptr[1] < '8' + && iptr[2] >= '0' && iptr[2] < '8' + && iptr[3] >= '0' && iptr[3] < '8') + { + *optr = (((iptr[1] - '0') << 6) | ((iptr[2] - '0') << 3) + | (iptr[3] - '0')); + iptr += 4; + } + else + *optr = *iptr++; + } + *optr = 0; +} + char * grub_find_root_device_from_mountinfo (const char *dir, char **relroot) { @@ -165,6 +186,9 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) entry.enc_root, entry.enc_path, &count) < 6) continue; + unescape (entry.enc_root); + unescape (entry.enc_path); + enc_path_len = strlen (entry.enc_path); /* Check that enc_path is a prefix of dir. The prefix must either be the entire string, or end with a slash, or be immediately followed