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

Commit

Permalink
fix(api): Fix TA crash meeting unicode input
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
howjmay committed May 16, 2019
1 parent 8a2eb57 commit 22dfaf5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions accelerator/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ typedef enum {
/**< NULL object in serializer */
SC_SERIALIZER_JSON_PARSE = 0x03 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
/**< Fail to parse JSON object in serializer */
SC_SERIALIZER_JSON_PARSE_UNICODE =
0x04 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
/**< unicode value in JSON */

// Cache module
SC_CACHE_NULL = 0x01 | SC_MODULE_CACHE | SC_SEVERITY_FATAL,
Expand Down
9 changes: 9 additions & 0 deletions serializer/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ status_t send_mam_req_deserialize(const char* const obj, send_mam_req_t* req) {
tryte_t* payload_trytes = (tryte_t*)malloc(payload_size * sizeof(tryte_t));
ascii_to_trytes(json_result->valuestring, payload_trytes);

// in case the payload is unicode, char more than 128 will result to an
// error status_t code
for (int i = 0; i < strlen(json_result->valuestring); i++) {
if (json_result->valuestring[i] & (unsigned)128) {
ret = SC_SERIALIZER_JSON_PARSE_UNICODE;
goto done;
}
}

req->payload_trytes = payload_trytes;
req->payload_trytes_size = payload_size;
} else {
Expand Down

0 comments on commit 22dfaf5

Please sign in to comment.