From: Seonah Moon Date: Tue, 17 Oct 2017 07:15:58 +0000 (+0900) Subject: [CID-28247, 37559] remove TOCTOU issues X-Git-Tag: submit/tizen_4.0/20171017.081943^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8fa5ca7b31206d7ef0c8cd14397169bef7ec6a5d;p=platform%2Fcore%2Fapi%2Fhttp.git [CID-28247, 37559] remove TOCTOU issues Change-Id: I3f1de6ce3a04dedbf9a91b662e0dbdc6f4f3f8e5 Signed-off-by: Seonah Moon --- diff --git a/packaging/capi-network-http.spec b/packaging/capi-network-http.spec index 2bab32a..ecc64c0 100644 --- a/packaging/capi-network-http.spec +++ b/packaging/capi-network-http.spec @@ -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 diff --git a/src/http_request.c b/src/http_request.c index 7a81029..0839334 100644 --- a/src/http_request.c +++ b/src/http_request.c @@ -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; diff --git a/test/http_test.c b/test/http_test.c index 7f959b6..19ded45 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -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);