[committed] Initialize pids in dwz_files_1

Tom de Vries tdevries@suse.de
Sat Mar 27 12:56:43 GMT 2021


Hi,

The loop dealing with waiting on the remaining children contains:
...
         if (res->res == -2)
           /* Skip hard links.  */
           continue;
...

The reason we need this is because the pids array isn't initialized in this
case, so the following code:
...
          if (pids[i] == 0)
            continue;
...
would otherwise read an uninitialized variable.

Fix this by:
- initializing the pids array, and
- removing the res->res == -2 code.

Committed to trunk.

Thanks,
- Tom

Initialize pids in dwz_files_1

2021-03-27  Tom de Vries  <tdevries@suse.de>

	* dwz.c (dwz_files_1): Initialize pids.  Simplify loop waiting on
	remaining children.

---
 dwz.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/dwz.c b/dwz.c
index bd40e90..3e7eb24 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16496,6 +16496,8 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
   if (max_forks > 1 && multifile == NULL)
     {
       pid_t pids[nr_files];
+      for (i = 0; i < nr_files; i++)
+	pids[i] = 0;
       for (i = 0; i < nr_files; i++)
 	{
 	  int thisret;
@@ -16529,11 +16531,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
       for (i = 0; i < nr_files; i++)
 	{
 	  int thisret;
-	  file = files[i];
 	  struct file_result *res = &resa[i];
-	  if (res->res == -2)
-	    /* Skip hard links.  */
-	    continue;
 	  if (pids[i] == 0)
 	    continue;
 	  thisret = wait_child_exit (pids[i], &pids[i], 1, res);


More information about the Dwz mailing list