]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix mtab update for "none" source, fix leak stable/v2.19
authorKarel Zak <kzak@redhat.com>
Wed, 20 Jul 2011 19:24:20 +0000 (21:24 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 20 Jul 2011 19:52:34 +0000 (21:52 +0200)
tab_parse.c:mnt_parse_mountinfo_line parses "none" in src as NULL,

tab_update.c:fprintf_mtab_fs sets m1 to NULL instead of "none" and
returns -ENOMEM
tab_update.c:update_table says "write entry failed: Success", as errno
hasn't been set, and gotos to leave, leaving mtab not updated.

Addresses-debian-bug: 634871
Reported-by: Tomas Janousek <tomi@nomi.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/mount/src/fs.c
shlibs/mount/src/tab_update.c
tests/ts/libmount/update

index 91d8d22420472c13cf63c75e0f7ef60d8c823b2d..d5bd16717186667b51041dc5f15c3a844a261068 100644 (file)
@@ -297,10 +297,11 @@ int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
 
        assert(fs);
 
-       if (source && !strcmp(source, "none"))
+       if (source && !strcmp(source, "none")) {
+               free(source);
                source = NULL;
-
-       if (source && strchr(source, '=')) {
+       }
+       else if (source && strchr(source, '=')) {
                if (blkid_parse_tag_string(source, &t, &v) != 0)
                        return -1;
        }
index 7617df83ba1ae94abc7dff3d777bc2c40b38b098..3666d76d5f673868cbb7b510a89ad8034593ad00 100644 (file)
@@ -480,20 +480,21 @@ err:
 static int fprintf_mtab_fs(FILE *f, struct libmnt_fs *fs)
 {
        char *o;
+       const char *src, *fstype;
        char *m1, *m2, *m3, *m4;
        int rc;
 
        assert(fs);
        assert(f);
 
+       src = mnt_fs_get_source(fs);
+       fstype = mnt_fs_get_fstype(fs);
        o = mnt_fs_strdup_options(fs);
-       if (!o)
-               return -ENOMEM;
 
-       m1 = mangle(mnt_fs_get_source(fs));
+       m1 = src ? mangle(src) : "none";
        m2 = mangle(mnt_fs_get_target(fs));
-       m3 = mangle(mnt_fs_get_fstype(fs));
-       m4 = mangle(o);
+       m3 = fstype ? mangle(fstype) : "none";
+       m4 = o ? mangle(o) : "rw";
 
        if (m1 && m2 && m3 && m4) {
                rc = fprintf(f, "%s %s %s %s %d %d\n",
@@ -505,11 +506,15 @@ static int fprintf_mtab_fs(FILE *f, struct libmnt_fs *fs)
        } else
                rc = -ENOMEM;
 
-       free(o);
-       free(m1);
+       if (src)
+               free(m1);
        free(m2);
-       free(m3);
-       free(m4);
+       if (fstype)
+               free(m3);
+       if (o) {
+               free(m4);
+               free(o);
+       }
 
        return rc;
 }
index db0369305311df8902454203eb96f3e6d8c7a348..0223fcf029979fbb80b39753b88f7acc4e76e197 100755 (executable)
@@ -34,6 +34,7 @@ $TESTPROG --add /dev/sda1 /mnt/foo ext3 "rw,bbb,ccc,fff=FFF,ddd,noexec"
 $TESTPROG --add /dev/sdb1 /mnt/bar ext3 "gg=G,ffff=f,ro,noatime"
 $TESTPROG --add /dev/sda2 /mnt/bar ext3 "rw,noatime"
 $TESTPROG --add /dev/sda1 /mnt/gogo ext3 "rw,noatime,nosuid"
+$TESTPROG --add none /proc proc "defaults"
 cp $LIBMOUNT_MTAB $TS_OUTPUT   # save the mtab aside
 ts_finalize_subtest            # checks the mtab