]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: Use waitpid() when waiting for mount helper child process
authorVratislav Podzimek <vpodzime@redhat.com>
Mon, 6 Nov 2017 10:28:17 +0000 (11:28 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 6 Nov 2017 12:05:04 +0000 (13:05 +0100)
Using wait() in a library may be problematic as it may reap some
totally unrelated child process instead of the just forked
one. That can result in the library call doing weird things and
returning bad return values, but also in a breakage of an
arbitrary other thing in the program using the library.

[[kzak@redhat.com: - use waitpid() for umount too
                   - keep the current codding style]

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c
libmount/src/context_umount.c

index c6a794d7e27c1db0e5aa9dfee558c3c3530b5a77..b5b57e6bf1e74d22ef568dd4fcb800a1e1cd6334 100644 (file)
@@ -576,6 +576,7 @@ static int exec_helper(struct libmnt_context *cxt)
 {
        char *o = NULL;
        int rc;
+       pid_t pid;
 
        assert(cxt);
        assert(cxt->fs);
@@ -590,7 +591,8 @@ static int exec_helper(struct libmnt_context *cxt)
 
        DBG_FLUSH;
 
-       switch (fork()) {
+       pid = fork();
+       switch (pid) {
        case 0:
        {
                const char *args[12], *type;
@@ -637,7 +639,7 @@ static int exec_helper(struct libmnt_context *cxt)
        default:
        {
                int st;
-               wait(&st);
+               waitpid(pid, &st, 0);
                cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
 
                DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d]",
index a8124629f38cb07aa76d042eab638ccb1cd207c2..e8fb37357c9ad5de0b29da8ca1e2d09534dbe987 100644 (file)
@@ -521,6 +521,7 @@ eperm:
 static int exec_helper(struct libmnt_context *cxt)
 {
        int rc;
+       pid_t pid;
 
        assert(cxt);
        assert(cxt->fs);
@@ -536,7 +537,8 @@ static int exec_helper(struct libmnt_context *cxt)
 
        DBG_FLUSH;
 
-       switch (fork()) {
+       pid = fork();
+       switch (pid) {
        case 0:
        {
                const char *args[10], *type;
@@ -581,7 +583,7 @@ static int exec_helper(struct libmnt_context *cxt)
        default:
        {
                int st;
-               wait(&st);
+               waitpid(pid, &st, 0);
                cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
 
                DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d]",