Skip to content

Commit 61b0efc

Browse files
authored
Merge pull request #7039 from embhorn/zd17127
Check for neg size in fp_read_unsigned_bin
2 parents 5caa71e + 27e9327 commit 61b0efc

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

wolfcrypt/src/tfm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4051,12 +4051,16 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
40514051
/* zero the int */
40524052
fp_zero (a);
40534053

4054+
if (c < 0) {
4055+
return FP_VAL;
4056+
}
4057+
40544058
if (c == 0) {
40554059
return FP_OKAY;
40564060
}
40574061

40584062
/* if input b excess max, then truncate */
4059-
if (c > 0 && (word32)c > maxC) {
4063+
if ((word32)c > maxC) {
40604064
int excess = (c - maxC);
40614065
c -= excess;
40624066
b += excess;

wolfcrypt/test/test.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16930,7 +16930,7 @@ static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
1693016930
goto done;
1693116931
}
1693216932
ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
16933-
#if !defined(WOLFSSL_SP_MATH) & !defined(WOLFSSL_SP_MATH_ALL)
16933+
#if defined(USE_INTEGER_HEAP_MATH)
1693416934
if (ret != 0)
1693516935
#else
1693616936
if (ret != ASN_GETINT_E)
@@ -16944,11 +16944,12 @@ static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
1694416944
if (ret != 0)
1694516945
return WC_TEST_RET_ENC_EC(ret);
1694616946
ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
16947-
#if !defined(WOLFSSL_SP_MATH) & !defined(WOLFSSL_SP_MATH_ALL)
16948-
if (ret != 0) {
16947+
#if defined(USE_INTEGER_HEAP_MATH)
16948+
if (ret != 0)
1694916949
#else
16950-
if (ret != ASN_GETINT_E) {
16950+
if (ret != ASN_GETINT_E)
1695116951
#endif
16952+
{
1695216953
ret = WC_TEST_RET_ENC_EC(ret);
1695316954
goto done;
1695416955
}

0 commit comments

Comments
 (0)