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

Commit

Permalink
fix(serialize): Fix unicode resulted error
Browse files Browse the repository at this point in the history
The unicode tag in api_send_transfer would causing TA SIGV.
Use the same technique which already used in send_mam_req_deserialize
to solve this problem.
  • Loading branch information
howjmay committed Jun 5, 2019
1 parent 20ba8cf commit 1f333bf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion accelerator/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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 =
SC_SERIALIZER_JSON_PARSE_ASCII =
0x04 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
/**< unicode value in JSON */
SC_SERIALIZER_INVALID_REQ = 0x05 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
Expand Down
12 changes: 10 additions & 2 deletions serializer/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ status_t ta_send_transfer_req_deserialize(const char* const obj,
if (json_result != NULL && json_result->valuestring != NULL) {
tag_len = strnlen(json_result->valuestring, NUM_TRYTES_TAG);

for (int i = 0; i < tag_len; i++) {
if (json_result->valuestring[i] & (unsigned)128) {
ret = SC_SERIALIZER_JSON_PARSE_ASCII;
goto done;
}
}

// If 'tag' is less than 27 trytes (NUM_TRYTES_TAG), expands it
if (tag_len < NUM_TRYTES_TAG) {
char new_tag[NUM_TRYTES_TAG + 1];
Expand Down Expand Up @@ -624,9 +631,10 @@ status_t send_mam_req_deserialize(const char* const obj, send_mam_req_t* req) {

// 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++) {
size_t payload_ascii_len = payload_size > 1;
for (int i = 0; i < payload_ascii_len; i++) {
if (json_result->valuestring[i] & (unsigned)128) {
ret = SC_SERIALIZER_JSON_PARSE_UNICODE;
ret = SC_SERIALIZER_JSON_PARSE_ASCII;
goto done;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/regression/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_send_transfer(self):
response[i]["content"] + ", status code = " +
response[i]["status_code"])

pass_case = [0, 1, 2, 3]
pass_case = [0, 1, 2, 3, 5, 6, 7, 8, 9, 10]
for i in range(len(response)):
if i in pass_case:
res_json = json.loads(response[i]["content"])
Expand All @@ -290,7 +290,7 @@ def test_send_transfer(self):
valid_trytes(res_json["signature_and_message_fragment"],
LEN_MSG_SIGN))
elif i == 4:
self.assertEqual(EMPTY_REPLY, response[i]["status_code"])
self.assertEqual(STATUS_CODE_500, response[i]["status_code"])
else:
self.assertEqual(STATUS_CODE_404, response[i]["status_code"])

Expand Down
4 changes: 2 additions & 2 deletions tests/test_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ extern "C" {
"RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNM" \
"VKWYGVA"
#define TRYTES_81_3 \
"FPPBU9AOXZHSJEWDCPWGCPKGOVIUWWPDTIIXDJUKYYNNPTWCGDWFBZLKVCLOKGYEHJUMABSTA9" \
"OP99999"
"BGBQJCVSOESTAVKHKD9QBNYVHUUEQUGZ9BEUAPG9HGQWAHMDAJXKDPUZPRBZVVIPRHMERPOBCD" \
"YB99999"
#define BUNDLE_HASH \
"LVXEVZABVCIFEDSCONKEVEYBSIRMXGHLJDKSKQHTKZC9ULEAPSLKOOWCCZJGWSIISDDSEVUQHV" \
"GPFOSIW"
Expand Down

0 comments on commit 1f333bf

Please sign in to comment.