From fb9d90d552a5043a994c9ba61f6876ac30143412 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 5 Apr 2011 14:17:51 +0200 Subject: [PATCH] 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" Signed-off-by: Karel Zak --- shlibs/mount/src/tab_parse.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 1bf88db56f..be85d47115 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); -- 2.47.3