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

Commit 688c5b4

Browse files
committed
fix(api): Fix errors in send_trytes
serialize/serialize.c: Return `SC_SERIALIZER_INVALID_REQ` if any element (trytes) in the requeting trytes list length not equal to NUM_TRYTES_SERIALIZED_TRANSACTION. utils/pow.c: Exit pow loop if tx == NULL which may happen if the requesting trytes is arbitrary tytes which means the transaction indext doesn't meet the real index.
1 parent c7410f0 commit 688c5b4

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

accelerator/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ typedef enum {
9797
SC_SERIALIZER_JSON_PARSE_UNICODE =
9898
0x04 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
9999
/**< unicode value in JSON */
100+
SC_SERIALIZER_INVALID_REQ = 0x05 | SC_MODULE_SERIALIZER | SC_SEVERITY_FATAL,
101+
/**< invald request value in JSON */
100102

101103
// Cache module
102104
SC_CACHE_NULL = 0x01 | SC_MODULE_CACHE | SC_SEVERITY_FATAL,

serializer/serializer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ static status_t ta_json_array_to_hash8019_array(cJSON const* const obj,
8282
cJSON* current_obj = NULL;
8383
cJSON_ArrayForEach(current_obj, json_item) {
8484
if (current_obj->valuestring != NULL) {
85+
if (strlen(current_obj->valuestring) !=
86+
NUM_TRYTES_SERIALIZED_TRANSACTION) {
87+
return SC_SERIALIZER_INVALID_REQ;
88+
}
8589
flex_trits_from_trytes(hash, NUM_TRITS_SERIALIZED_TRANSACTION,
8690
(tryte_t const*)current_obj->valuestring,
8791
NUM_TRYTES_SERIALIZED_TRANSACTION,

utils/pow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ status_t ta_pow(const bundle_transactions_t* bundle,
8282
ctrunk = iota_flex_digest(tx_trits, NUM_TRITS_SERIALIZED_TRANSACTION);
8383
tx = (iota_transaction_t*)utarray_prev(bundle, tx);
8484
free(nonce);
85-
} while (cur_idx != 0);
85+
} while (cur_idx != 0 && tx != NULL);
8686

8787
done:
8888
free(ctrunk);

0 commit comments

Comments
 (0)