Fix build warnings for gcc9 44/221044/1 accepted/tizen/unified/20191230.120929 submit/tizen/20191230.112257
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 26 Dec 2019 12:38:59 +0000 (21:38 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 26 Dec 2019 12:39:03 +0000 (21:39 +0900)
Change-Id: I57f8c411c130d0b48b9979d5eb0eaa859f239335

agent/download-agent-http-mgr.c
agent/download-agent-http-msg-handler.c
agent/download-agent-mime-util.c
packaging/download-provider.spec
provider-interface/download-provider-interface.c
provider/download-provider-db.c

index 790c60b..1ea3dff 100755 (executable)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -149,13 +150,11 @@ void __parsing_user_request_header(char *user_request_header,
                        break;
                pos++;
        }
-       len = strlen(pos) + 1;
-       value = (char *)calloc(1, len + 1);
-       if (!value) {
-               DA_LOGE("Fail to calloc");
+       value = strdup(pos);
+       if (value == NULL) {
+               DA_LOGE("Fail to copy pos");
                goto ERR;
        }
-       strncpy(value, pos, len);
        *out_field = field;
        *out_value = value;
        DA_SECURE_LOGD("field[%s], value[%s]", field, value);
@@ -1120,6 +1119,7 @@ static proxy_info_t *__get_proxy_info()
        char password[DA_MAX_PASSWORD_LEN] = {0, };
        char host[DA_MAX_PROXY_ADDR_LEN] = {0, }; // ip:port
        char *proxy_uri = get_proxy_address(); // scheme://userinfo@ip:port
+       int ret = 0;
 
        if (proxy_uri && !strstr(proxy_uri, "0.0.0.0")) {
                proxy_info = (proxy_info_t *)calloc(1, sizeof(proxy_info_t));
@@ -1131,13 +1131,15 @@ static proxy_info_t *__get_proxy_info()
 
                char *found = strrchr(proxy_uri, '@');
                if (found) {
-                       char userinfo[DA_MAX_USER_NAME_LEN + DA_MAX_PASSWORD_LEN + 1] = {0, };
-                       strncpy(userinfo, proxy_uri, strlen(proxy_uri) - strlen(found));
+                       size_t userinfo_len = strlen(proxy_uri) - strlen(found);
+                       char *userinfo = strndup(proxy_uri, userinfo_len);
                        if (strstr(userinfo, SCHEME_DELIMETER))
                                sscanf(userinfo, "%7[^:/]://%255[^:]:%255s", scheme, user_name, password);
                        else
                                sscanf(userinfo, "%255[^:]:%255s", user_name, password);
 
+                       free(userinfo);
+
                        sscanf(found + 1, "%63s", host);
                        if (strlen(host) == 0) {
                                DA_LOGE("Invalid proxy address");
@@ -1149,15 +1151,13 @@ static proxy_info_t *__get_proxy_info()
                        if (strlen(scheme) == 0)
                                strncpy(scheme, DEFAULT_SCHEME, DA_MAX_SCHEME_LEN - 1);
 
-                       size_t addr_len = strlen(scheme) + strlen(host) + 4;
-                       proxy_info->addr = (char *)calloc(1, addr_len);
-                       if (!proxy_info->addr) {
-                               DA_LOGE("Failed to calloc");
+                       ret = asprintf(&proxy_info->addr, "%s://%s", scheme, host);
+                       if (ret == -1 || proxy_info->addr == NULL) {
+                               DA_LOGE("Failed to set proxy_info->addr");
                                free(proxy_info);
                                free(proxy_uri);
                                return DA_NULL;
                        }
-                       snprintf(proxy_info->addr, addr_len - 1, "%s://%s", scheme, host);
                } else {
                        proxy_info->addr = strdup(proxy_uri);
                }
index b352947..a1dc55a 100755 (executable)
@@ -461,7 +461,8 @@ http_header_options_t *__parsing_N_create_option_str(char *org_str)
        }
 
        DA_SECURE_LOGD("option_field = [%s], option_value = [%s]",
-                       option_field, option_value);
+                       option_field ? option_field : "",
+                       option_value ? option_value : "");
 
        if (option_field || option_value) {
                option = __create_http_header_option(
@@ -822,9 +823,7 @@ da_bool_t http_msg_response_get_content_disposition(
                        if (decoded_str) {
                                char* file_name;
                                DA_SECURE_LOGD("Url decoded str = [%s]", decoded_str);
-                               file_name = (char*)calloc(1, strlen(decoded_str) + 1);
-                               strncpy(file_name, decoded_str, strlen(decoded_str));
-
+                               file_name = strdup(decoded_str);
                                NULL_CHECK_AND_FREE(wanted_str);
                                curl_free(decoded_str);
                                decoded_str = NULL;
index 12188b6..e5b76e4 100755 (executable)
@@ -180,10 +180,8 @@ da_ret_t da_mime_get_ext_name(char *mime, char **ext)
                temp++;
 
        DA_SECURE_LOGD("final extension name:[%s]", temp);
-       *ext = (char*)calloc(1, strlen(temp) + 1);
-       if (*ext != DA_NULL) {
-               strncpy(*ext, temp, strlen(temp));
-       } else  {
+       *ext = strdup(temp);
+       if (*ext == DA_NULL) {
                ret = DA_ERR_FAIL_TO_MEMALLOC ;
                goto ERR ;
        }
@@ -343,10 +341,7 @@ da_bool_t da_get_file_name_from_url(char *url, char **name, char **extension)
                }
                //              DA_SECURE_LOGD("file name BEFORE removing prohibited character = %s", name_buff);
                delete_prohibited_char(name_buff, strlen(name_buff));
-               len_name = strlen(name_buff);
-               *name = (char*) calloc(1, len_name + 1);
-               if (*name)
-                       strncpy(*name, name_buff, len_name);
+               *name = strdup(name_buff);
        }
                DA_SECURE_LOGD("Extracted file name : %s, extension : %s", *name, *extension);
 ERR:
index 7bd8a72..7e82c7b 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       download-provider
 Summary:    Download the contents in background
-Version:    2.1.117
+Version:    2.1.118
 Release:    0
 Group:      Development/Libraries
 License:    Apache-2.0
index 9863540..8146447 100755 (executable)
@@ -241,7 +241,7 @@ static int __create_socket()
        bzero(&clientaddr, sizeof clientaddr);
        clientaddr.sun_family = AF_UNIX;
        memset(clientaddr.sun_path, 0x00, sizeof(clientaddr.sun_path));
-       strncpy(clientaddr.sun_path, IPC_SOCKET, strlen(IPC_SOCKET));
+       strncpy(clientaddr.sun_path, IPC_SOCKET, sizeof(clientaddr.sun_path) - 1);
        clientaddr.sun_path[strlen(IPC_SOCKET)] = '\0';
        if (connect(sockfd,
                (struct sockaddr*)&clientaddr, sizeof(clientaddr)) < 0) {
index 91f35cf..ff97988 100755 (executable)
@@ -973,7 +973,7 @@ int dp_db_new_header(void *handle, const int id, const char *field, const char *
                return -1;
        }
        if (field == NULL) {
-               TRACE_ERROR("check field:%s", field);
+               TRACE_ERROR("field is null");
                return -1;
        }
        int errorcode = SQLITE_OK;