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

Commit 22dfaf5

Browse files
committed
fix(api): Fix TA crash meeting unicode input
The original TA would crash if it met unicode input, but now, it will return an error status_t code to reflect the situation that catch an unicode input.
1 parent 8a2eb57 commit 22dfaf5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

accelerator/errors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ typedef enum {
8787
/**< NULL object in serializer */
8888
SC_SERIALIZER_JSON_PARSE = 0x03 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
8989
/**< Fail to parse JSON object in serializer */
90+
SC_SERIALIZER_JSON_PARSE_UNICODE =
91+
0x04 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
92+
/**< unicode value in JSON */
9093

9194
// Cache module
9295
SC_CACHE_NULL = 0x01 | SC_MODULE_CACHE | SC_SEVERITY_FATAL,

serializer/serializer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,15 @@ status_t send_mam_req_deserialize(const char* const obj, send_mam_req_t* req) {
521521
tryte_t* payload_trytes = (tryte_t*)malloc(payload_size * sizeof(tryte_t));
522522
ascii_to_trytes(json_result->valuestring, payload_trytes);
523523

524+
// in case the payload is unicode, char more than 128 will result to an
525+
// error status_t code
526+
for (int i = 0; i < strlen(json_result->valuestring); i++) {
527+
if (json_result->valuestring[i] & (unsigned)128) {
528+
ret = SC_SERIALIZER_JSON_PARSE_UNICODE;
529+
goto done;
530+
}
531+
}
532+
524533
req->payload_trytes = payload_trytes;
525534
req->payload_trytes_size = payload_size;
526535
} else {

0 commit comments

Comments
 (0)