Add NULL check before strdup() 10/255010/2 accepted/tizen_5.5_unified tizen_5.5 accepted/tizen/5.5/unified/20210315.014246 submit/tizen_5.5/20210311.093620
authorYunjin Lee <yunjin-.lee@samsung.com>
Thu, 11 Mar 2021 08:21:52 +0000 (17:21 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Thu, 11 Mar 2021 09:07:35 +0000 (18:07 +0900)
- Add NULL check before strdup() for the case that the
tokenized string is NULL

Change-Id: I87ee79bfad27763aaa400b3b3a2df0d18e556ab5
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
src/privilege_information.c

index d8e001cfc3b7f8fdc8d116f5956b42036c9dec70..ed8f8ecbbf8cd32437b9beae84e41e31d9a0d1e2 100755 (executable)
@@ -173,8 +173,10 @@ int privilege_info_get_display_name(const char *api_version, const char *privile
                        temp = token;
                        token = strtok_r(NULL, "/", &save);
                }
-               *display_name = strdup(temp);
-               TryReturn(*display_name != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
+               if (temp != NULL) {
+                       *display_name = strdup(temp);
+                       TryReturn(*display_name != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
+               }
                free(tempPrivilege);
        } else if (ret == PRVINFO_ERROR_NONE) {
                TryReturn(string_id != NULL, *display_name = NULL, PRVINFO_ERROR_NONE, "No DID for privilege : %s", privilege);