Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
fix: Fix miscellaneous request payload
Browse files Browse the repository at this point in the history
Without giving terminate character `\0`, the HTTP payload
may contain some miscellaneous string.
  • Loading branch information
howjmay committed Jan 4, 2020
1 parent 0a944b4 commit 01196e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion accelerator/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,14 @@ static int ta_http_handler(void *cls, struct MHD_Connection *connection, const c
// While upload_data_size > 0 process upload_data
if (*upload_data_size > 0) {
if (http_req->request == NULL) {
http_req->request = (char *)malloc(*upload_data_size);
http_req->request = (char *)malloc((*upload_data_size) + 1);
if (http_req->request == NULL) {
ta_log_error("%s\n", "Not enough size for allocating HTTP request payload.");
goto cleanup;
}

strncpy(http_req->request, upload_data, *upload_data_size);
http_req->request[*upload_data_size] = 0;
} else {
ret = MHD_NO;
ta_log_error("%s\n", "MHD_NO");
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "accelerator/common_core.h"
#include "iota_api_mock.hh"

using ::testing::_;
using ::testing::AtLeast;
using ::testing::ElementsAreArray;
using ::testing::_;

APIMock APIMockObj;
iota_config_t tangle;
Expand Down

0 comments on commit 01196e3

Please sign in to comment.