Fix mp_radix_size off by 1 error

This commit is contained in:
Eric Blankenhorn 2020-09-10 09:58:26 -05:00
parent 39b5448601
commit 78a1670334
4 changed files with 8 additions and 9 deletions

View File

@ -335,7 +335,7 @@ int mp_unitest_mul(const char* strZ, const char* strX, const char* strY, int ver
}
mp_radix_size(&z, 16, &radixZ_size);
bufZ = (char*)XMALLOC(radixZ_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if(bufZ != NULL) {
mp_toradix(&z, bufZ, 16);
bufZ[radixZ_size] ='\0';
@ -350,7 +350,7 @@ int mp_unitest_mul(const char* strZ, const char* strX, const char* strY, int ver
mp_radix_size(&y, 16, &radixY_size);
radixX_size = max(radixX_size, radixY_size);
buf = (char*)XMALLOC(radixX_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if(buf != NULL) {
mp_toradix(&x, buf, 16);
buf[radixX_size] ='\0';
@ -410,7 +410,7 @@ int mp_unitest_mulmod(const char* strZ, const char* strX, const char* strY,
}
mp_radix_size(&z, 16, &radixZ_size);
bufZ = (char*)XMALLOC(radixZ_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if(bufZ != NULL) {
mp_toradix(&z, bufZ, 16);
bufZ[radixZ_size] ='\0';
@ -427,7 +427,7 @@ int mp_unitest_mulmod(const char* strZ, const char* strX, const char* strY,
mp_radix_size(&m, 16, &radixM_size);
radixX_size = max(radixX_size, max(radixY_size, radixM_size));
buf = (char*)XMALLOC(radixX_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if(buf != NULL) {
mp_toradix(&x, buf, 16);
buf[radixX_size] ='\0';
@ -491,7 +491,7 @@ int mp_unitest_exptmod(const char* strZ, const char* strX, const char* strY,
}
mp_radix_size(&z, 16, &radixZ_size);
bufZ = (char*)XMALLOC(radixZ_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if(bufZ != NULL) {
mp_toradix(&z, bufZ, 16);
bufZ[radixZ_size] ='\0';
@ -508,7 +508,7 @@ int mp_unitest_exptmod(const char* strZ, const char* strX, const char* strY,
mp_radix_size(&m, 16, &radixM_size);
radixX_size = max(radixX_size, max(radixY_size, radixM_size));
buf = (char*)XMALLOC(radixX_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if(buf != NULL) {
mp_toradix(&x, buf, 16);
buf[radixX_size] ='\0';

View File

@ -46562,7 +46562,6 @@ char *wolfSSL_BN_bn2hex(const WOLFSSL_BIGNUM *bn)
WOLFSSL_MSG("mp_radix_size failure");
return NULL;
}
len += 1; /* add one for null terminator */
buf = (char*)XMALLOC(len, NULL, DYNAMIC_TYPE_OPENSSL);
if (buf == NULL) {

View File

@ -5242,7 +5242,7 @@ int mp_radix_size (mp_int *a, int radix, int *size)
}
/* digs is the digit count */
digs = 0;
digs = 1;
/* if it's negative add one for the sign */
if (a->sign == MP_NEG) {

View File

@ -5451,7 +5451,7 @@ int mp_radix_size (mp_int *a, int radix, int *size)
}
/* digs is the digit count */
digs = 0;
digs = 1;
/* if it's negative add one for the sign */
if (a->sign == FP_NEG) {