Skip to content

Commit 2b0aac6

Browse files
committed
Fix a buffer overflow in the C reference decoder
Thanks to Christian Reitter and Dr. Jochen Hoenicke for discovering this issue and suggesting a fix.
1 parent bfc7167 commit 2b0aac6

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

ref/c/segwit_addr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const char *input)
9797
++(*data_len);
9898
}
9999
hrp_len = input_len - (1 + *data_len);
100-
if (hrp_len < 1 || *data_len < 6) {
100+
if (1 + *data_len >= input_len || *data_len < 6) {
101101
return 0;
102102
}
103103
*(data_len) -= 6;

ref/c/tests.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static const char* invalid_address[] = {
9191
"BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2",
9292
"bc1rw5uspcuh",
9393
"bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90",
94+
"bca0w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90234567789035",
9495
"BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P",
9596
"tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7",
9697
"bc1zw508d6qejxtdg4y5r3zarvaryvqyzf3du",

0 commit comments

Comments
 (0)