Skip to contentSkip to conversation

libmount: Get rid of an unnecessary check

PATCH Applied Namhyung Kim 2 participants 8 messages Sep 25, 2013 – Sep 26, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 libmount: Get rid of an unnecessary check

libmount_debug_mask was OR'ed to MNT_DEBUG_INIT so it should be non-null. Thus the check is pointless.

---
 libmount/src/init.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libmount/src/init.c +1 -1
index 4e5f489..8d468d0 100644
@@ -40,7 +40,7 @@ void mnt_init_debug(int mask)
 
 	libmount_debug_mask |= MNT_DEBUG_INIT;
 
-	if (libmount_debug_mask && libmount_debug_mask != MNT_DEBUG_INIT) {
+	if (libmount_debug_mask != MNT_DEBUG_INIT) {
 		const char *ver = NULL;
 		const char **features = NULL, **p;
 
Signature · 1 line
1.7.9.2
#1 lore raw

PATCH 2/4 libmount: Free splitted optstr's when error occurred

When strdup() failed, u, v and f optstr's should be freed.

---
 libmount/src/fs.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
libmount/src/fs.c +5 -1
index c95cdc7..e3a2e1a 100644
@@ -774,8 +774,12 @@ int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr)
 		if (rc)
 			return rc;
 		n = strdup(optstr);
-		if (!n)
+		if (!n) {
+			free(u);
+			free(v);
+			free(f);
 			return -ENOMEM;
+		}
 	}
 
 	free(fs->fs_optstr);
Signature · 1 line
1.7.9.2
maintainer Applied
#2 lore raw

Re: [PATCH 2/4] libmount: Free splitted optstr's when error occurred

Quoted 2 lines · Namhyung Kim
 libmount/src/fs.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#3 lore raw

PATCH 3/4 libmount: Set each optstr's to NULL if failed

In reply to Namhyung Kim

When mnt_split_optstr() failed in the middle, vfs, fs, user optstr's are freed but not reset. It can lead to double frees at the end of mnt_fs_{ap,pre}pend_options().

---
 libmount/src/optstr.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
libmount/src/optstr.c +9 -3
index 5e9e708..17b129d 100644
@@ -567,12 +567,18 @@ int mnt_split_optstr(const char *optstr, char **user, char **vfs,
 			rc = __mnt_optstr_append_option(fs, name, namesz,
 								val, valsz);
 		if (rc) {
-			if (vfs)
+			if (vfs) {
 				free(*vfs);
-			if (fs)
+				*vfs = NULL;
+			}
+			if (fs) {
 				free(*fs);
-			if (user)
+				*fs = NULL;
+			}
+			if (user) {
 				free(*user);
+				*user = NULL;
+			}
 			return rc;
 		}
 	}
Signature · 1 line
1.7.9.2
maintainer
#4 lore raw

Re: [PATCH 3/4] libmount: Set each optstr's to NULL if failed

Quoted 3 lines · Namhyung Kim

When mnt_split_optstr() failed in the middle, vfs, fs, user optstr's are freed but not reset. It can lead to double frees at the end of mnt_fs_{ap,pre}pend_options().

It's bug that mnt_fs_{ap,pre}pend_options() functions use the pointers after failed mnt_split_optstr().

Anyway, it's probably better to be robust here so applied and also fixed mnt_fs_{ap,pre}pend_options().

Thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw

PATCH 4/4 libmount: Remove stale comment on mnt_context_mount()

In reply to Namhyung Kim

The commit f9906424 ("libmount: add post-mount checks to detect ro/rw") added necessary check so the comment is not valid anymore.

---
 libmount/src/context_mount.c |    5 -----
 1 file changed, 5 deletions(-)
libmount/src/context_mount.c +0 -5
index d6691eb..3215aef 100644
@@ -973,11 +973,6 @@ int mnt_context_mount(struct libmnt_context *cxt)
 		rc = mnt_context_prepare_update(cxt);
 	if (!rc)
 		rc = mnt_context_do_mount(cxt);
-
-	/* TODO: if mtab update is expected then check if the
-	 * target is really mounted read-write to avoid 'ro' in
-	 * mtab and 'rw' in /proc/mounts.
-	 */
 	if (!rc)
 		rc = mnt_context_update_tabs(cxt);
 	return rc;
Signature · 1 line
1.7.9.2
maintainer Applied
#6 lore raw

Re: [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount()

Quoted 2 lines · Namhyung Kim
 libmount/src/context_mount.c |    5 -----
 1 file changed, 5 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer Applied
#7 lore raw
In reply to Namhyung Kim
Quoted 2 lines · Namhyung Kim
 libmount/src/init.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks. (The same code we had in libblkid, fixed too.)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com