[PATCH 5/7] child_spawn: fix possible fd_close() on uninited value

From: Roman I Khimov <khimov_at_altell.ru>
Date: Fri, 13 Mar 2015 17:24:24 +0300

If SKALIBS_HASPOSIXSPAWN is not defined and (n == 0), then we can easily end
up calling fd_close() on error handling, since 'p' is never inited when n is 0.

Found by Clang's scan-build.
---
 src/libstddjb/child_spawn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c
index a9938c7..0f08c3c 100644
--- a/src/libstddjb/child_spawn.c
+++ b/src/libstddjb/child_spawn.c
_at_@ -183,8 +183,8 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const
  errsp0:
   fd_close(syncpipe[0]) ;
 #endif
-  i = n ;
  errp:
+  i = n ;
   while (i--)
   {
     fd_close(p[i][1]) ;
-- 
2.1.4
Received on Fri Mar 13 2015 - 14:24:24 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC