From: Youngjae Shin Date: Thu, 29 Aug 2013 07:31:55 +0000 (+0900) Subject: remove system() function for leaks of security X-Git-Tag: accepted/tizen/generic/20140317.083658~69 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f8e5b892959bd9c0ef361109e5819356dcd61d6f;hp=f57591e76d9450227f027c29556c38904b77fe45;p=platform%2Fcore%2Fconnectivity%2Fnfc-manager-neard.git remove system() function for leaks of security Change-Id: I5d3396357410e2412a52f11df32e685367b1a029 --- diff --git a/daemon/net_nfc_server_util.c b/daemon/net_nfc_server_util.c index 3596c51..c816910 100644 --- a/daemon/net_nfc_server_util.c +++ b/daemon/net_nfc_server_util.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -59,6 +58,61 @@ static const char osp_launch_type_condition[] = "condition"; +static inline int _mkdir_recursive(char *path, mode_t mode) +{ + char *found = path; + + while (found) + { + char tmp_ch; + + if ('\0' == found[1]) + break; + + found = strchr(found+1, '/'); + + if (found) + { + int ret; + DIR *exist; + + tmp_ch = *found; + *found = '\0'; + + exist = opendir(path); + if (NULL == exist) + { + if (ENOENT == errno) + { + ret = mkdir(path, mode); + if (-1 == ret) + { + char buf[1024]; + DEBUG_ERR_MSG("mkdir() Failed(%s)", strerror_r(errno, buf, sizeof(buf))); + return -1; + } + } + else + { + char buf[1024]; + DEBUG_ERR_MSG("opendir() Failed(%s)", strerror_r(errno, buf, sizeof(buf))); + return -1; + } + } + else + { + closedir(exist); + } + *found = tmp_ch; + } + else + { + mkdir(path, mode); + } + } + return 0; +} + static bool _net_nfc_app_util_change_file_owner_permission(FILE *file) { char *buffer = NULL; @@ -116,9 +170,9 @@ static bool _net_nfc_app_util_change_file_owner_permission(FILE *file) static net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data) { + int ret; net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; char file_name[1024] = { 0, }; - struct stat st; FILE *fp = NULL; if (data == NULL) @@ -130,22 +184,11 @@ static net_nfc_error_e net_nfc_app_util_store_ndef_message(data_s *data) snprintf(file_name, sizeof(file_name), "%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_MESSAGE); - if (stat(file_name, &st) == -1) + ret = _mkdir_recursive(file_name, 0755); + if (-1 == ret) { - int ret; - char command[1024]; - - SECURE_LOGD("path doesn't exist, do mkdir : %s", file_name); - - snprintf(command, sizeof(command), "mkdir -p -m 755 %s", file_name); - - ret = system(command); - - if (stat(file_name, &st) == -1) - { - DEBUG_ERR_MSG("mkdir failed(%d)", ret); - return NET_NFC_UNKNOWN_ERROR; - } + DEBUG_ERR_MSG("_mkdir_recursive() Failed"); + return NET_NFC_UNKNOWN_ERROR; } /* create file */