crypto: Fix buffer overflow in b58tobin.

release/2020-06
Andrew Kozlik 4 years ago committed by Tomas Susanka
parent f34e2382fa
commit 20dd1ddc60

@ -46,6 +46,9 @@ typedef uint32_t b58_almostmaxint_t;
static const b58_almostmaxint_t b58_almostmaxint_mask =
((((b58_maxint_t)1) << b58_almostmaxint_bits) - 1);
// Decodes a null-terminated Base58 string `b58` to binary and writes the result
// at the end of the buffer `bin` of size `*binszp`. On success `*binszp` is set
// to the number of valid bytes at the end of the buffer.
bool b58tobin(void *bin, size_t *binszp, const char *b58) {
size_t binsz = *binszp;
@ -108,20 +111,18 @@ bool b58tobin(void *bin, size_t *binszp, const char *b58) {
}
}
// Count canonical base58 byte count
// locate the most significant byte
binu = bin;
for (i = 0; i < binsz; ++i) {
if (binu[i]) {
if (zerocount > i) {
/* result too large */
return false;
}
if (binu[i]) break;
}
break;
}
--*binszp;
// prepend the correct number of null-bytes
if (zerocount > i) {
/* result too large */
return false;
}
*binszp += zerocount;
*binszp = binsz - i + zerocount;
return true;
}

Loading…
Cancel
Save