[CID-26106] fixed NULL termination error 18/154718/1 accepted/tizen/unified/20171013.190320 submit/tizen/20171012.045027
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 11 Oct 2017 07:12:59 +0000 (16:12 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 11 Oct 2017 07:23:35 +0000 (16:23 +0900)
Change-Id: Ia4fa442ed58a6c49a6b56b63368700e0db5493df

packaging/capi-network-http.spec
test/http_test.c

index d44f5ad..2bab32a 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.30
+Version:       0.0.31
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index f86564d..7f959b6 100644 (file)
@@ -157,8 +157,8 @@ int _write_message_body(http_transaction_h transaction, const char *file_path)
 {
        struct stat file_info;
        FILE *fp;
-       size_t file_size;
        size_t chunk_size = 50;
+       size_t result = 0;
        char *buf = malloc(chunk_size + 1);
 
        if (stat(file_path, &file_info) != 0) {
@@ -173,22 +173,14 @@ int _write_message_body(http_transaction_h transaction, const char *file_path)
                return -1;
        }
 
-       file_size = file_info.st_size;
-
        fp = fopen(file_path, "rb");
        if (!fp) {
                free(buf);
                return -1;
        }
 
-       while (fread(buf, 1, chunk_size, fp) > 0) {
-               if (file_size < chunk_size)
-                       http_transaction_request_write_body(transaction, strndup(buf, file_size));
-               else
-                       http_transaction_request_write_body(transaction, strdup(buf));
-
-               file_size -= chunk_size;
-       }
+       while ((result = fread(buf, 1, chunk_size, fp)) > 0)
+               http_transaction_request_write_body(transaction, strndup(buf, result));
 
        free(buf);
        fclose(fp);
@@ -452,7 +444,7 @@ int test_post_chunk(void)
                return 0;
        }
 
-       ret = http_transaction_request_set_uri(transaction, "http://httpbin.org/post");
+       ret = http_transaction_request_set_uri(transaction, "http://posttestserver.com/post.php");
        if (ret != 0) {
                ERR("Fail to set URI", ret);
                return 0;