diff options
author | Karel Zak | 2011-04-05 14:17:51 +0200 |
---|---|---|
committer | Karel Zak | 2011-04-05 14:17:51 +0200 |
commit | fb9d90d552a5043a994c9ba61f6876ac30143412 (patch) | |
tree | 3a2eda3109a719d24b73ccedce5d89907b29681c /shlibs/mount/src/tab_parse.c | |
parent | build-sys: fix distcheck for term-utils (diff) | |
download | kernel-qcow2-util-linux-fb9d90d552a5043a994c9ba61f6876ac30143412.tar.gz kernel-qcow2-util-linux-fb9d90d552a5043a994c9ba61f6876ac30143412.tar.xz kernel-qcow2-util-linux-fb9d90d552a5043a994c9ba61f6876ac30143412.zip |
libmount: fix parsing of mountinfo from 2.6.39
The /proc/self/mountinfo file uses " - " field as a separator between
optional fields and next fields in the file. The '-' char could be
used in the fields (for example in UUIDs), so it's necessary to check
for whole " - " string rather than for '-' char only.
Reported-by: "Aneesh Kumar K. V" <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/tab_parse.c')
-rw-r--r-- | shlibs/mount/src/tab_parse.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 1bf88db56..be85d4711 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -113,9 +113,9 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) */ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) { - int rc; + int rc, end = 0; unsigned int maj, min; - char *fstype, *src; + char *fstype, *src, *p; rc = sscanf(s, "%u " /* (1) id */ "%u " /* (2) parent */ @@ -123,11 +123,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) "%ms " /* (4) mountroot */ "%ms " /* (5) target */ "%ms" /* (6) vfs options (fs-independent) */ - "%*[^-]" /* (7) optional fields */ - "- " /* (8) separator */ - "%ms " /* (9) FS type */ - "%ms " /* (10) source */ - "%ms", /* (11) fs options (fs specific) */ + "%n", /* number of read bytes */ &fs->id, &fs->parent, @@ -135,11 +131,28 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) &fs->root, &fs->target, &fs->vfs_optstr, + &end); + + if (rc >= 7 && end > 0) + s += end; + + /* (7) optional fields, terminated by " - " */ + p = strstr(s, " - "); + if (!p) { + DBG(TAB, mnt_debug("mountinfo parse error: not found separator")); + return -EINVAL; + } + s = p + 3; + + rc += sscanf(s, "%ms " /* (8) FS type */ + "%ms " /* (9) source */ + "%ms", /* (10) fs options (fs specific) */ + &fstype, &src, &fs->fs_optstr); - if (rc == 10) { + if (rc >= 10) { fs->flags |= MNT_FS_KERNEL; fs->devno = makedev(maj, min); |