diff options
author | Karel Zak | 2011-07-20 21:24:20 +0200 |
---|---|---|
committer | Karel Zak | 2011-07-20 21:24:20 +0200 |
commit | b5962110d274b06388d83f7bcee6b72ebc442170 (patch) | |
tree | 76db54de3218cc377e74057b4ac85ed8b41d2512 /libmount/src/tab_update.c | |
parent | libmount: cleanup code for "none" source and fstype, fix mem leak (diff) | |
download | kernel-qcow2-util-linux-b5962110d274b06388d83f7bcee6b72ebc442170.tar.gz kernel-qcow2-util-linux-b5962110d274b06388d83f7bcee6b72ebc442170.tar.xz kernel-qcow2-util-linux-b5962110d274b06388d83f7bcee6b72ebc442170.zip |
libmount: fix mtab update for "none" source
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>
Diffstat (limited to 'libmount/src/tab_update.c')
-rw-r--r-- | libmount/src/tab_update.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index 88125bfbb..39d61e66c 100644 --- a/libmount/src/tab_update.c +++ b/libmount/src/tab_update.c @@ -409,21 +409,21 @@ err: */ static int fprintf_mtab_fs(FILE *f, struct libmnt_fs *fs) { - char *o; + const char *o, *src, *fstype; char *m1, *m2, *m3, *m4; int rc; assert(fs); assert(f); - o = mnt_fs_strdup_options(fs); - if (!o) - return -ENOMEM; + src = mnt_fs_get_source(fs); + fstype = mnt_fs_get_fstype(fs); + o = mnt_fs_get_options(fs); - 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", @@ -435,11 +435,13 @@ 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); return rc; } |