1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

bignum: check values of decimals and exponent in bn_format

This commit is contained in:
Pavol Rusnak 2019-02-16 15:45:06 +01:00
parent 2ac59892b7
commit 4211ce389f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -989,6 +989,12 @@ void bn_divmod1000(bignum256 *a, uint32_t *r)
size_t bn_format(const bignum256 *amnt, const char *prefix, const char *suffix, unsigned int decimals, int exponent, bool trailing, char *out, size_t outlen)
{
// sanity check, 2**256 ~ 10**77; we should never need decimals/exponent bigger than that
if (decimals > 80 || exponent < -20 || exponent > 80) {
memzero(out, outlen);
return 0;
}
size_t prefixlen = prefix ? strlen(prefix) : 0;
size_t suffixlen = suffix ? strlen(suffix) : 0;