public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] libmount: Get rid of an unnecessary check
@ 2013-09-25 15:32 Namhyung Kim
  2013-09-25 15:32 ` [PATCH 2/4] libmount: Free splitted optstr's when error occurred Namhyung Kim
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Namhyung Kim @ 2013-09-25 15:32 UTC (permalink / raw)
  To: util-linux

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

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 libmount/src/init.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmount/src/init.c b/libmount/src/init.c
index 4e5f489..8d468d0 100644
--- a/libmount/src/init.c
+++ b/libmount/src/init.c
@@ -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;
 
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] libmount: Free splitted optstr's when error occurred
  2013-09-25 15:32 [PATCH 1/4] libmount: Get rid of an unnecessary check Namhyung Kim
@ 2013-09-25 15:32 ` Namhyung Kim
  2013-09-26  7:50   ` Karel Zak
  2013-09-25 15:32 ` [PATCH 3/4] libmount: Set each optstr's to NULL if failed Namhyung Kim
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Namhyung Kim @ 2013-09-25 15:32 UTC (permalink / raw)
  To: util-linux

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

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 libmount/src/fs.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libmount/src/fs.c b/libmount/src/fs.c
index c95cdc7..e3a2e1a 100644
--- a/libmount/src/fs.c
+++ b/libmount/src/fs.c
@@ -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);
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] libmount: Set each optstr's to NULL if failed
  2013-09-25 15:32 [PATCH 1/4] libmount: Get rid of an unnecessary check Namhyung Kim
  2013-09-25 15:32 ` [PATCH 2/4] libmount: Free splitted optstr's when error occurred Namhyung Kim
@ 2013-09-25 15:32 ` Namhyung Kim
  2013-09-26  7:53   ` Karel Zak
  2013-09-25 15:32 ` [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount() Namhyung Kim
  2013-09-26  7:49 ` [PATCH 1/4] libmount: Get rid of an unnecessary check Karel Zak
  3 siblings, 1 reply; 8+ messages in thread
From: Namhyung Kim @ 2013-09-25 15:32 UTC (permalink / raw)
  To: util-linux

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().

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 libmount/src/optstr.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index 5e9e708..17b129d 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -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;
 		}
 	}
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount()
  2013-09-25 15:32 [PATCH 1/4] libmount: Get rid of an unnecessary check Namhyung Kim
  2013-09-25 15:32 ` [PATCH 2/4] libmount: Free splitted optstr's when error occurred Namhyung Kim
  2013-09-25 15:32 ` [PATCH 3/4] libmount: Set each optstr's to NULL if failed Namhyung Kim
@ 2013-09-25 15:32 ` Namhyung Kim
  2013-09-26  7:53   ` Karel Zak
  2013-09-26  7:49 ` [PATCH 1/4] libmount: Get rid of an unnecessary check Karel Zak
  3 siblings, 1 reply; 8+ messages in thread
From: Namhyung Kim @ 2013-09-25 15:32 UTC (permalink / raw)
  To: util-linux

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

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 libmount/src/context_mount.c |    5 -----
 1 file changed, 5 deletions(-)

diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index d6691eb..3215aef 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -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;
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] libmount: Get rid of an unnecessary check
  2013-09-25 15:32 [PATCH 1/4] libmount: Get rid of an unnecessary check Namhyung Kim
                   ` (2 preceding siblings ...)
  2013-09-25 15:32 ` [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount() Namhyung Kim
@ 2013-09-26  7:49 ` Karel Zak
  3 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2013-09-26  7:49 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: util-linux

On Thu, Sep 26, 2013 at 12:32:03AM +0900, Namhyung Kim wrote:
>  libmount/src/init.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

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

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] libmount: Free splitted optstr's when error occurred
  2013-09-25 15:32 ` [PATCH 2/4] libmount: Free splitted optstr's when error occurred Namhyung Kim
@ 2013-09-26  7:50   ` Karel Zak
  0 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2013-09-26  7:50 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: util-linux

On Thu, Sep 26, 2013 at 12:32:04AM +0900, Namhyung Kim wrote:
>  libmount/src/fs.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] libmount: Set each optstr's to NULL if failed
  2013-09-25 15:32 ` [PATCH 3/4] libmount: Set each optstr's to NULL if failed Namhyung Kim
@ 2013-09-26  7:53   ` Karel Zak
  0 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2013-09-26  7:53 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: util-linux

On Thu, Sep 26, 2013 at 12:32:05AM +0900, Namhyung Kim wrote:
> 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

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount()
  2013-09-25 15:32 ` [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount() Namhyung Kim
@ 2013-09-26  7:53   ` Karel Zak
  0 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2013-09-26  7:53 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: util-linux

On Thu, Sep 26, 2013 at 12:32:06AM +0900, Namhyung Kim wrote:
>  libmount/src/context_mount.c |    5 -----
>  1 file changed, 5 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-09-26  7:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-25 15:32 [PATCH 1/4] libmount: Get rid of an unnecessary check Namhyung Kim
2013-09-25 15:32 ` [PATCH 2/4] libmount: Free splitted optstr's when error occurred Namhyung Kim
2013-09-26  7:50   ` Karel Zak
2013-09-25 15:32 ` [PATCH 3/4] libmount: Set each optstr's to NULL if failed Namhyung Kim
2013-09-26  7:53   ` Karel Zak
2013-09-25 15:32 ` [PATCH 4/4] libmount: Remove stale comment on mnt_context_mount() Namhyung Kim
2013-09-26  7:53   ` Karel Zak
2013-09-26  7:49 ` [PATCH 1/4] libmount: Get rid of an unnecessary check Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox