On 04/03/2013 05:58 PM, Michal Židek wrote:
The first patch fixes coverity bugs mentioned in ticked
https://fedorahosted.org/sssd/ticket/1865

The second fixes wrong condition after waitpid.

Michal


I forgot to change one of the debug messages to use the new debug level macros.

New patch attached.

Michal

>From 784585b97ecc74febc7c1a19a4c882a7d425a792 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 |  8 ++++----
 src/tools/tools_util.c  | 11 +++++------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/tools/sss_userdel.c b/src/tools/sss_userdel.c
index 2cf7759..ac87a73 100644
--- a/src/tools/sss_userdel.c
+++ b/src/tools/sss_userdel.c
@@ -101,15 +101,15 @@ 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..1ad5326 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(SSSDBG_CRIT_FAILURE, ("waitpid failed\n"));
+            ret = errno;
+            goto done;
+        }
     }
 
     ret = EOK;
-- 
1.7.11.2

>From 027f79a0d41dc2e79ca30a9d50844a4b707fb09e 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