The first patch fixes coverity bugs mentioned in ticked
https://fedorahosted.org/sssd/ticket/1865

The second fixes wrong condition after waitpid.

Michal
>From 613ad8eadb4a2845f9ef1de26b2d8a55570d90c3 Mon Sep 17 00:00:00 2001
From: Michal Zidek <mzi...@redhat.com>
Date: Wed, 3 Apr 2013 17:04:41 +0200
Subject: [PATCH 1/2] Check for waitpid failure at wrong place.

Coverity bugs.

https://fedorahosted.org/sssd/ticket/1865
---
 src/tools/sss_userdel.c |  9 +++++----
 src/tools/tools_util.c  | 11 +++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/tools/sss_userdel.c b/src/tools/sss_userdel.c
index 2cf7759..ac24c00 100644
--- a/src/tools/sss_userdel.c
+++ b/src/tools/sss_userdel.c
@@ -101,15 +101,16 @@ static int kick_user(struct tools_ctx *tctx)
         }
 
         while((child_pid = waitpid(pid, &status, 0)) > 0) {
-            if (child_pid == -1) {
-                DEBUG(1, ("waitpid failed\n"));
-                return errno;
-            }
 
             if (WIFEXITED(status)) {
                 break;
             }
         }
+        if (child_pid == -1) {
+            DEBUG(SSSDBG_CRIT_FAILURE, ("waitpid failed\n"));
+            return errno;
+        }
+
     }
 
     return EOK;
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 85164c6..e1c8689 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -538,12 +538,6 @@ int run_userdel_cmd(struct tools_ctx *tctx)
         }
 
         while((child_pid = waitpid(pid, &status, 0)) > 0) {
-            if (child_pid == -1) {
-                DEBUG(1, ("waitpid failed\n"));
-                ret = errno;
-                goto done;
-            }
-
             if (WIFEXITED(status)) {
                 ret = WEXITSTATUS(status);
                 if (ret != 0) {
@@ -567,6 +561,11 @@ int run_userdel_cmd(struct tools_ctx *tctx)
                 goto done;
             }
         }
+        if (child_pid == -1) {
+            DEBUG(1, ("waitpid failed\n"));
+            ret = errno;
+            goto done;
+        }
     }
 
     ret = EOK;
-- 
1.7.11.2

>From 361213f589fba1e693343623378bf150cc4cf951 Mon Sep 17 00:00:00 2001
From: Michal Zidek <mzi...@redhat.com>
Date: Wed, 3 Apr 2013 17:43:01 +0200
Subject: [PATCH 2/2] Wrong condition after waitpid.

On success, waitpid() returns pid of terminated child, not 0.
---
 src/tools/nscd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tools/nscd.c b/src/tools/nscd.c
index 365383c..b9f2ba8 100644
--- a/src/tools/nscd.c
+++ b/src/tools/nscd.c
@@ -70,7 +70,7 @@ int flush_nscd_cache(enum nscd_db flush_db)
             errno = 0;
             ret = waitpid(nscd_pid, &status, 0);
         } while (ret == -1 && errno == EINTR);
-        if (ret == 0) {
+        if (ret > 0) {
             if (WIFEXITED(status)) {
                 ret = WEXITSTATUS(status);
                 if (ret > 0) {
-- 
1.7.11.2

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to