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

Commit 0f35ef4

Browse files
author
HYChang
committed
Fix invalid memory operation when sending transfer with invalid tag
Sending invalid tag with `iri-host` flag enabled will cause SEGV. The ta_pow_flex didn't handle the NULL pointer when ta_pow_dcurl returned NULL. Close #625
1 parent 8d0947e commit 0f35ef4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

accelerator/core/pow.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ flex_trit_t* ta_pow_flex(const flex_trit_t* const trits_in, const uint8_t mwm) {
4141
flex_trits_to_trytes(trytes_in, NUM_TRYTES_SERIALIZED_TRANSACTION, trits_in, NUM_TRITS_SERIALIZED_TRANSACTION,
4242
NUM_TRITS_SERIALIZED_TRANSACTION);
4343
int8_t* ret_trytes = ta_pow_dcurl(trytes_in, mwm, 0);
44+
if (ret_trytes == NULL) {
45+
return NULL;
46+
}
4447
memcpy(nonce_trytes, ret_trytes + NUM_TRYTES_SERIALIZED_TRANSACTION - NUM_TRYTES_NONCE, NUM_TRYTES_NONCE);
4548

4649
flex_trit_t* nonce_trits = (flex_trit_t*)calloc(NUM_TRITS_NONCE, sizeof(flex_trit_t));

tests/api/driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void test_send_transfer(void) {
105105
"\"address\":\"" TRYTES_81_1 "\"}";
106106
tryte_t test_transfer_message[TEST_TRANSFER_MESSAGE_LEN + 1] = {};
107107
gen_rand_trytes(TEST_TRANSFER_MESSAGE_LEN, test_transfer_message);
108-
const int len = strlen(json_template) + TEST_TRANSFER_MESSAGE_LEN;
108+
const int len = strlen(json_template) + TEST_TRANSFER_MESSAGE_LEN + 1;
109109
char* json = (char*)malloc(sizeof(char) * len);
110110
snprintf(json, len, json_template, test_transfer_message);
111111
char* json_result;

tests/regression/test_suite/send_transfer.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ def test_unicode_address(self):
8282
res = API("/transaction/",
8383
post_data=map_field(self.post_field, self.query_string[10]))
8484
self._verify_pass(res)
85+
86+
# Zero value, tryte maessage, invalid tag, tryte address (fail)
87+
@test_logger
88+
def test_invalid_tag(self):
89+
res = API("/transaction/",
90+
post_data=map_field(self.post_field, self.query_string[11]))
91+
self._verify_pass(res)
92+
93+
# Zero value, tryte maessage, tryte tag, invalid address (fail)
94+
@test_logger
95+
def test_invalid_address(self):
96+
res = API("/transaction/",
97+
post_data=map_field(self.post_field, self.query_string[12]))
98+
self._verify_pass(res)
99+
100+
# Zero value, tryte maessage, invalid tag, invalid address (fail)
101+
@test_logger
102+
def test_invalid_tag_and_address(self):
103+
res = API("/transaction/",
104+
post_data=map_field(self.post_field, self.query_string[13]))
105+
self._verify_pass(res)
85106

86107
# Time statistics
87108
@test_logger
@@ -109,6 +130,8 @@ def setUpClass(cls):
109130
rand_msg = gen_rand_trytes(30)
110131
rand_tag = gen_rand_trytes(27)
111132
rand_addr = gen_rand_trytes(81)
133+
rand_invalid_tag = gen_rand_trytes(999)
134+
rand_invalid_addr = gen_rand_trytes(999)
112135
cls.post_field = ["value", "message", "tag", "address"]
113136
cls.query_string = [[420, rand_msg, rand_tag, rand_addr],
114137
[0, rand_msg, rand_tag, rand_addr],
@@ -120,7 +143,11 @@ def setUpClass(cls):
120143
[0, None, rand_tag, rand_addr],
121144
[0, rand_msg, None, rand_addr],
122145
[0, rand_msg, rand_tag, None],
123-
[0, rand_msg, rand_tag, "我思故我在"]]
146+
[0, rand_msg, rand_tag, "我思故我在"],
147+
[0, rand_msg, "ololaola", rand_addr],
148+
[0, rand_msg, rand_tag, "dio"],
149+
[0, rand_msg, "olaolaola", "dio"],
150+
]
124151

125152
def _verify_pass(self, res):
126153
self.assertEqual(STATUS_CODE_200, res["status_code"])

0 commit comments

Comments
 (0)