Skip to content

Commit 5a63965

Browse files
Fix buffer OOB write
1 parent e00b2ea commit 5a63965

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/common_utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ void getEthAddressFromRawKey(const uint8_t raw_pubkey[static 65],
235235
}
236236

237237
void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65],
238-
char out[static ADDRESS_LENGTH * 2],
238+
char out[static (ADDRESS_LENGTH * 2) + 1],
239239
uint64_t chainId) {
240240
uint8_t hashAddress[CX_KECCAK_256_SIZE];
241241
CX_ASSERT(cx_keccak_256_hash(raw_pubkey + 1, 64, hashAddress));
242242
getEthAddressStringFromBinary(hashAddress + 12, out, chainId);
243243
}
244244

245245
bool getEthAddressStringFromBinary(uint8_t *address,
246-
char out[static ADDRESS_LENGTH * 2],
246+
char out[static (ADDRESS_LENGTH * 2) + 1],
247247
uint64_t chainId) {
248248
// save some precious stack space
249249
union locals_union {
@@ -295,7 +295,7 @@ bool getEthAddressStringFromBinary(uint8_t *address,
295295
}
296296
}
297297
}
298-
out[40] = '\0';
298+
out[ADDRESS_LENGTH * 2] = '\0';
299299

300300
return true;
301301
}

src/common_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ void getEthAddressFromRawKey(const uint8_t raw_pubkey[static 65],
7171
uint8_t out[static ADDRESS_LENGTH]);
7272

7373
void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65],
74-
char out[static ADDRESS_LENGTH * 2],
74+
char out[static (ADDRESS_LENGTH * 2) + 1],
7575
uint64_t chainId);
7676

7777
bool getEthAddressStringFromBinary(uint8_t *address,
78-
char out[static ADDRESS_LENGTH * 2],
78+
char out[static (ADDRESS_LENGTH * 2) + 1],
7979
uint64_t chainId);
8080

8181
bool getEthDisplayableAddress(uint8_t *in, char *out, size_t out_len, uint64_t chainId);

0 commit comments

Comments
 (0)