svace: fix closing potentially negative fd 89/197989/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 17 Jan 2019 11:38:48 +0000 (12:38 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 17 Jan 2019 11:38:48 +0000 (12:38 +0100)
This commit fixes following issue reported by svace:

 "Variable 'cinfo.prstatus_fd', which may receive negative value at
  crash-manager.c:588 by calling function 'set_crash_info' at
  crash-manager.c:1267, is used at crash-manager.c:1332 by calling
  function 'close'."

Change-Id: Ie625bc8ac5eb16a84bb7b139b569c6189e1a5e25

src/crash-manager/crash-manager.c

index 1cba5ee..e2c6a0f 100644 (file)
@@ -1202,7 +1202,7 @@ static void free_crash_info(struct crash_info *cinfo)
 
 int main(int argc, char *argv[])
 {
-       struct crash_info cinfo = {0};
+       struct crash_info cinfo = {.prstatus_fd = -1};
 
        /* Execute dump_systemstate in parallel */
        static int dump_state_pid;
@@ -1319,7 +1319,8 @@ int main(int argc, char *argv[])
                launch_crash_popup(&cinfo);
 
 exit:
-       close(cinfo.prstatus_fd);
+       if (cinfo.prstatus_fd >= 0)
+               close(cinfo.prstatus_fd);
        free(crash_temp_path);
        free(crash_root_path);
        free(crash_crash_path);