From e466f775bb62219d824f099cfa781aa61a15da0a Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Thu, 11 Mar 2021 17:21:52 +0900 Subject: [PATCH] Add NULL check before strdup() - Add NULL check before strdup() for the case that the tokenized string is NULL Change-Id: I87ee79bfad27763aaa400b3b3a2df0d18e556ab5 Signed-off-by: Yunjin Lee --- src/privilege_information.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/privilege_information.c b/src/privilege_information.c index d8e001c..ed8f8ec 100755 --- a/src/privilege_information.c +++ b/src/privilege_information.c @@ -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); -- 2.7.4