Fix potentially undefined behavior 09/178009/3 accepted/tizen/unified/20180518.120452 submit/tizen/20180510.103449
authorSunmin Lee <sunm.lee@samsung.com>
Thu, 28 Sep 2017 10:05:07 +0000 (19:05 +0900)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Mon, 7 May 2018 11:24:16 +0000 (13:24 +0200)
The documentation does not describe the behavior of the access()
function for a NULL path argument, which can be returned by mkdtemp()

Change-Id: I9c5c08eb424f5e9bdab248682b00e9cb895c7afa
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
[ Cherry-picked from tizen_4.0 branch, extended commit message ]
Signed-off-by: Mateusz Moscicki <m.moscicki2@partner.samsung.com>
src/crash-manager/crash-manager.c
src/dump_systemstate/dump_systemstate.c

index 28d9cd0b4c54dbd5f96f152d95219b8c4cea67a9..cc409d41d837aa3ebe53308a7163794b56dbffa3 100644 (file)
@@ -256,7 +256,7 @@ error:
 static int set_crash_info(int argc, char *argv[])
 {
        int ret;
-       char *temp_dir_ret;
+       char *temp_dir_ret = NULL;
        time_t time_val;
        struct tm loc_tm;
 
@@ -283,7 +283,7 @@ static int set_crash_info(int argc, char *argv[])
                return -1;
        }
        temp_dir_ret = mkdtemp(crash_info.temp_dir);
-       if (access(temp_dir_ret, F_OK)) {
+       if (!temp_dir_ret || access(temp_dir_ret, F_OK)) {
                _E("Failed to mkdtemp for temp_dir");
                return -1;
        }
index 09467b18c135cdfadde27970ed2499246395ba1f..0bf881e91e6c6a3da434c0ef3c7b265e4c2fd93c 100644 (file)
@@ -106,8 +106,9 @@ int main(int argc, char *argv[])
                case 'f':
                        arg_file = optarg;
                        break;
-               case '?': printf("\n");
+               case '?':
                case 'h':
+                       printf("\n");
                        usage();
                        ret = 0;
                        goto exit;