[Security vulnerability] Replace strncmp() with strcmp() 49/200849/2
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 4 Mar 2019 08:39:05 +0000 (17:39 +0900)
committerseonah moon <seonah1.moon@samsung.com>
Wed, 6 Mar 2019 01:08:16 +0000 (01:08 +0000)
In case comparing whole string, use strcmp().

Change-Id: Iacb667cacece5eb8a964c8dc2219ff0d17908bf3

agent/download-agent-file.c
agent/download-agent-http-mgr.c
agent/download-agent-http-msg-handler.c
agent/download-agent-mime-util.c
agent/download-agent-plugin-libcurl.c
provider/download-provider-plugin-download-agent.c

index 06b76f9..50212ff 100755 (executable)
@@ -439,8 +439,8 @@ da_ret_t __decide_file_path(da_info_t *da_info)
 
        if (!extension) {
                if (file_info->mime_type
-                               && strncmp(file_info->mime_type, "application/x-xz", strlen("application/x-xz"))
-                               && strncmp(file_info->mime_type, "application/rss+xml", strlen("application/rss+xml")))
+                               && strcmp(file_info->mime_type, "application/x-xz")
+                               && strcmp(file_info->mime_type, "application/rss+xml"))
                        extension = __get_extension_name(file_info->mime_type, file_name_from_header, url);
                else
                        extension = __get_extension_name(NULL, file_name_from_header, url);
index 7cc8b3b..a971237 100755 (executable)
@@ -879,8 +879,7 @@ da_ret_t __check_resume_download_is_available(
                goto ERR;
        }
 
-       if (origin_ETag && new_ETag &&
-                       0 != strncmp(origin_ETag, new_ETag, strlen(new_ETag))) {
+       if (origin_ETag && new_ETag && strcmp(origin_ETag, new_ETag)) {
                DA_LOGE("ETag is not identical! revoke!");
                /* FIXME Later : Need to detail error exception handling */
                ret = DA_ERR_NETWORK_FAIL;
@@ -1167,7 +1166,7 @@ da_ret_t __handle_event_http_header(http_raw_data_t *raw_data, da_info_t *da_inf
                        DA_LOGE("Fail to raf mode value from response header");
                } else {
                        DA_LOGI("[RAF] val[%s:%s]", HTTP_FIELD_RAF_MODE, val);
-                       if (strncmp(val, "yes", strlen("yes")) == 0) {
+                       if (strcmp(val, "yes") == 0) {
                                DA_MUTEX_LOCK(&(http_info->mutex_state));
                                http_info->state = HTTP_STATE_DOWNLOAD_STARTED;
                                DA_MUTEX_UNLOCK(&(http_info->mutex_state));
index 92d54c3..b352947 100755 (executable)
@@ -711,8 +711,7 @@ void http_msg_response_set_content_type(http_msg_response_t *http_msg_response,
        b_ret = __get_http_header_for_field(http_msg_response,
                        HTTP_FIELD_CONTENT_TYPE, &header);
        if (b_ret) {
-               if (header->raw_value && (!strncmp(header->raw_value, in_type,
-                                               strlen(header->raw_value))))
+               if (header->raw_value && !strcmp(header->raw_value, in_type))
                        return;
 
                DA_SECURE_LOGD("exchange Content-Type to [%s] from [%s]", in_type, header->value);
index cb8eef7..12188b6 100755 (executable)
@@ -78,8 +78,7 @@ da_bool_t is_ambiguous_MIME_Type(const char *in_mime_type)
        int index = 0;
        int list_size = sizeof(ambiguous_MIME_Type_list) / sizeof(const char *);
        for (index = 0 ; index < list_size ; index++) {
-               if (0 == strncmp(in_mime_type, ambiguous_MIME_Type_list[index],
-                                       strlen(ambiguous_MIME_Type_list[index]))) {
+               if (0 == strcmp(in_mime_type, ambiguous_MIME_Type_list[index])) {
                        //DA_SECURE_LOGD("It is ambiguous! [%s]", ambiguous_MIME_Type_list[index]);
                        return DA_TRUE;
                }
@@ -125,7 +124,7 @@ da_ret_t da_mime_get_ext_name(char *mime, char **ext)
                DA_LOGV("No extension list");
 #ifdef _SAMSUNG_MIME_POLICY
                for (i = 0; i < MAX_SEC_MIME_TABLE_INDEX; i++) {
-                       if (strncmp(sec_mime_table[i].mime, mime, strlen(mime)) == 0) {
+                       if (strcmp(sec_mime_table[i].mime, mime) == 0) {
                                strncpy(ext_temp, sec_mime_table[i].ext, DA_MAX_STR_LEN-1);
                                ret = DA_RESULT_OK;
                                break;
@@ -141,8 +140,7 @@ da_ret_t da_mime_get_ext_name(char *mime, char **ext)
                         *  try to search common extension name from table
                         *  with first mime type at extension list*/
                        for (i = 0; i < MAX_EXT_TABLE_INDEX; i++) {
-                               if (strncmp(ext_trans_table[i].standard, *extlist,
-                                                       strlen(*extlist)) == 0) {
+                               if (strcmp(ext_trans_table[i].standard, *extlist) == 0) {
                                        memset(ext_temp, 0x00, DA_MAX_STR_LEN);
                                        strncpy(ext_temp, ext_trans_table[i].normal, DA_MAX_STR_LEN-1);
                                        break;
@@ -158,13 +156,12 @@ da_ret_t da_mime_get_ext_name(char *mime, char **ext)
 
        if (strlen(ext_temp) < 1) {
                /* If there is no mime string for OMA descriptor mime type */
-               if (strncmp(DD_MIME_STR, mime, strlen(DD_MIME_STR)) == 0) {
+               if (strcmp(DD_MIME_STR, mime) == 0) {
                        strncpy(ext_temp, DD_EXT_STR, DA_MAX_STR_LEN - 1);
                        ret = DA_RESULT_OK;
                        /* If there is no extension name for "applicaion/vnd.oma.drm.messeages"
                         *  at shared-mime-info*/
-               } else if (strncmp(DRM_MIME_MSG_STR, mime, strlen(DRM_MIME_MSG_STR)) ==
-                               0) {
+               } else if (strcmp(DRM_MIME_MSG_STR, mime) == 0) {
                        strncpy(ext_temp, DRM_EXT_STR, DA_MAX_STR_LEN - 1);
                        /* If there is extension name at extlist, the return value can have an error.*/
                        ret = DA_RESULT_OK;
index a7173a7..87826a2 100755 (executable)
@@ -177,9 +177,7 @@ void __store_header(void *msg, da_info_t *da_info, size_t header_size,
        }
 
        // FIXME later : check status code and redirection case check.
-
-       if (strncmp(msg, HTTP_FIELD_END_OF_FIELD,
-                               strlen(HTTP_FIELD_END_OF_FIELD)) == 0) {
+       if (strcmp(msg, HTTP_FIELD_END_OF_FIELD) == 0) {
                long status = 0;
                CURLcode res;
                CURL *curl;
index aea7966..27cee73 100755 (executable)
@@ -547,8 +547,7 @@ static int __dp_is_ambiguous_mime_type(const char *mime_type)
        int index = 0;
        int listSize = sizeof(ambiguous_mime_type_list) / sizeof(const char *);
        for (index = 0; index < listSize; index++) {
-               if (0 == strncmp(mime_type, ambiguous_mime_type_list[index],
-                                       strlen(ambiguous_mime_type_list[index]))) {
+               if (0 == strcmp(mime_type, ambiguous_mime_type_list[index])) {
                        TRACE_DEBUG("It is ambiguous");
                        return 0;
                }
@@ -585,7 +584,7 @@ static dp_content_type __dp_get_content_type(const char *mime, const char *file_
 
        /* Search a content type from mime table. */
        for (i = 0; i < DP_MAX_MIME_TABLE_NUM; i++) {
-               if (strncmp(mime_table[i].mime, temp_mime, strlen(temp_mime)) == 0) {
+               if (strcmp(mime_table[i].mime, temp_mime) == 0) {
                        type = mime_table[i].content_type;
                        break;
                }