[CID-28247, 37559] remove TOCTOU issues 19/156119/2 accepted/tizen/unified/20171018.062617 submit/tizen/20171017.081913
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 17 Oct 2017 07:15:58 +0000 (16:15 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 17 Oct 2017 07:56:37 +0000 (16:56 +0900)
Change-Id: I3f1de6ce3a04dedbf9a91b662e0dbdc6f4f3f8e5
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-http.spec
src/http_request.c
test/http_test.c

index 2bab32a..ecc64c0 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.31
+Version:       0.0.32
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index 7a81029..0839334 100644 (file)
@@ -282,13 +282,21 @@ int _open_upload_file(http_transaction_h http_transaction)
 {
        __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
        __http_request_h *request = transaction->request;
+
        struct stat file_info;
+       FILE *fp = fopen(request->upload_file, "rb");
+       if (!fp) {
+               ERR("Failed to open file!!");
+               return HTTP_ERROR_OPERATION_FAILED;
+       }
 
        if (stat(request->upload_file, &file_info) != 0) {
                ERR("stat() is failed.");
+               fclose(fp);
                return HTTP_ERROR_OPERATION_FAILED;
        }
-       request->fp = fopen(request->upload_file, "rb");
+
+       request->fp = fp;
        request->upload_size = (curl_off_t)file_info.st_size;
 
        return HTTP_ERROR_NONE;
index 7f959b6..19ded45 100644 (file)
@@ -155,24 +155,11 @@ void _register_callbacks(http_transaction_h transaction)
 
 int _write_message_body(http_transaction_h transaction, const char *file_path)
 {
-       struct stat file_info;
        FILE *fp;
        size_t chunk_size = 50;
        size_t result = 0;
        char *buf = malloc(chunk_size + 1);
 
-       if (stat(file_path, &file_info) != 0) {
-               ERR("stat() is failed", -1);
-               free(buf);
-               return -1;
-       }
-
-       if (!S_ISREG(file_info.st_mode)) {
-               ERR("path is not a regular file", -1);
-               free(buf);
-               return -1;
-       }
-
        fp = fopen(file_path, "rb");
        if (!fp) {
                free(buf);
@@ -438,6 +425,9 @@ int test_post_chunk(void)
        printf("Input path: ");
        ret = scanf("%1023s", path);
 
+       if (strlen(path) < 1)
+               return 0;
+
        ret = http_session_open_transaction(session, HTTP_METHOD_POST, &transaction);
        if (ret != 0) {
                ERR("Fail to open transaction", ret);