Replace sprintf with snprintf 97/69797/4 accepted/tizen/common/20160524.150704 accepted/tizen/mobile/20160525.004050 accepted/tizen/wearable/20160525.004134 submit/tizen/20160524.071953
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 17 May 2016 01:20:44 +0000 (10:20 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 17 May 2016 09:52:23 +0000 (18:52 +0900)
Change-Id: I61320cda38a0cefd35750675119dfd2c88c57e82
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-http.spec
src/http_header.c
test/http_test.c

index e586ffd..4ef03e8 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.5
+Version:       0.0.6
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index 269e416..bdba24a 100644 (file)
@@ -26,6 +26,7 @@ struct curl_slist* _get_header_list(http_transaction_h http_transaction)
        GHashTableIter iter;
        gpointer key = NULL;
        gpointer value = NULL;
+       int header_len = 0;
 
        if (!header->hash_table)
                return NULL;
@@ -33,10 +34,15 @@ struct curl_slist* _get_header_list(http_transaction_h http_transaction)
        g_hash_table_iter_init(&iter, header->hash_table);
 
        while (g_hash_table_iter_next(&iter, &key, &value)) {
-               header_str = (gchar *)malloc(sizeof(gchar) * (strlen(key) + 1 + 1 + strlen(value) + 1));
-               sprintf(header_str, "%s: %s", (gchar*)key, (gchar*)value);
+               header_len = sizeof(gchar) * (strlen(key) + 1 + 1 + strlen(value) + 1);
+               header_str = (gchar *)malloc(header_len);
+               if (header_str == NULL)
+                       return NULL;
+
+               snprintf(header_str, header_len, "%s: %s", (gchar*)key, (gchar*)value);
                DBG("Header Field: %s\n", header_str);
                header->header_list = curl_slist_append(header->header_list, header_str);
+
                free(header_str);
        }
 
index 32e1d27..1ad23f2 100644 (file)
@@ -215,7 +215,7 @@ int test_simple_post(void)
        http_transaction_set_ready_to_write(transaction, TRUE);
        http_transaction_request_write_body(transaction, post_msg);
 
-       sprintf(field_value, "%d", (int)strlen(post_msg));
+       snprintf(field_value, sizeof(field_value), "%d", (int)strlen(post_msg));
        printf("[dbg] post size (%s)\n", field_value);
        http_transaction_header_add_field(transaction, "Content-Length", field_value);