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

Commit 5a19644

Browse files
committed
fix(http): Report when requested msg too long
We currently assume all the size of requests of `api_send_transfer` in smaller than one transaction. To notify client who sent oversize message in `send_transfer`, now, tangle-accelerator will report the error mesage that the size of message is oversize.
1 parent 6ce1f4c commit 5a19644

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

accelerator/core/serializer/serializer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ status_t ta_send_transfer_req_deserialize(const char* const obj, ta_send_transfe
539539
req->msg_len = msg_len * 3;
540540
flex_trits_from_trytes(req->message, req->msg_len, (const tryte_t*)json_result->valuestring, msg_len, msg_len);
541541
}
542+
543+
if (req->msg_len > NUM_TRYTES_MESSAGE) {
544+
ret = SC_SERIALIZER_MESSAGE_OVERRUN;
545+
ta_log_error("%s\n", ta_error_to_string(ret));
546+
goto done;
547+
}
548+
542549
} else {
543550
// 'message' does not exists, set to DEFAULT_MSG
544551
req->msg_len = DEFAULT_MSG_LEN * 3;

common/ta_errors.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const char* ta_error_to_string(status_t err) {
4848
return "Unicode value in JSON\n";
4949
case SC_SERIALIZER_INVALID_REQ:
5050
return "Invalid request value in JSON\n";
51+
case SC_SERIALIZER_MESSAGE_OVERRUN:
52+
return "Message length is out of valid size\n";
5153
case SC_CACHE_NULL:
5254
return "NULL object in cache\n";
5355
case SC_CACHE_FAILED_RESPONSE:

common/ta_errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ typedef enum {
113113
/**< Unicode value in JSON */
114114
SC_SERIALIZER_INVALID_REQ = 0x05 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
115115
/**< Invald request value in JSON */
116+
SC_SERIALIZER_MESSAGE_OVERRUN = 0x06 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
117+
/**< Message length is out of valid size */
116118

117119
// Cache module
118120
SC_CACHE_NULL = 0x01 | SC_MODULE_CACHE | SC_SEVERITY_FATAL,

connectivity/common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ status_t set_response_content(status_t ret, char **json_result) {
6868
ta_log_error("%s\n", "SC_HTTP_BAD_REQUEST");
6969
*json_result = strdup(STR_HTTP_BAD_REQUEST);
7070
break;
71+
case SC_SERIALIZER_MESSAGE_OVERRUN:
72+
http_ret = SC_HTTP_BAD_REQUEST;
73+
ta_log_error("%s\n", ta_error_to_string(ret));
74+
*json_result = strdup(STR_HTTP_BAD_REQUEST_MESSAGE_OVERSIZE);
75+
break;
7176
default:
7277
http_ret = SC_HTTP_INTERNAL_SERVICE_ERROR;
7378
ta_log_error("%s\n", "SC_HTTP_INTERNAL_SERVICE_ERROR");

connectivity/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616

1717
#define STR_HTTP_NOT_FOUND "{\"message\": \"Request not found\"}"
1818
#define STR_HTTP_BAD_REQUEST "{\"message\": \"Invalid request header\"}"
19+
#define STR_HTTP_BAD_REQUEST_MESSAGE_OVERRUN "{\"message\": \"In body 'message', requested message is too long.\"}"
1920
#define STR_HTTP_INTERNAL_SERVICE_ERROR "{\"message\": \"Internal service error\"}"
2021
#define STR_HTTP_REQUEST_SIZE_EXCEED "{\"message\": \"Request size exceed\"}"
2122

0 commit comments

Comments
 (0)