lib/hcrypto: mpz2BN return NULL if mp_ubin_size(s) returns zero
If mp_ubin_size(s) returns zero then mp_to_ubin() will fail and not return MP_OKAY. If MP_OKAY is not returned, NULL is returned to the caller of mpz2BN(). This change avoids the unnecessary memory allocation and function calls. It also removes a dereference after null warning from coverity. Change-Id: I52ff2c166964e41cb4eef1dac637904bf2bf13bf
This commit is contained in:
@@ -456,8 +456,11 @@ mpz2BN(mp_int *s)
|
||||
void *p;
|
||||
|
||||
size = mp_ubin_size(s);
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
p = malloc(size);
|
||||
if (p == NULL && size != 0)
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = mp_to_ubin(s, p, SIZE_MAX, NULL);
|
||||
|
Reference in New Issue
Block a user