Skip to content

Commit d6759bc

Browse files
extra sanity check on RSA decrypt argument
1 parent 46a7719 commit d6759bc

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

tests/api/test_rsa.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,10 @@ int test_wc_RsaPublicEncryptDecrypt(void)
822822
ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
823823
&key), 0);
824824
ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
825-
/* Pass bad args - tested in another testing function.*/
825+
826+
/* Pass bad args - additionally tested in another testing function.*/
827+
ExpectIntEQ(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, inLen - 1,
828+
&key), RSA_BUFFER_E);
826829

827830
WC_FREE_VAR(in, NULL);
828831
WC_FREE_VAR(plain, NULL);

wolfcrypt/src/rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3638,7 +3638,7 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
36383638
word32 j;
36393639
int start = (int)((size_t)pad - (size_t)key->data);
36403640

3641-
for (j = 0; j < key->dataLen; j++) {
3641+
for (j = 0; j < key->dataLen && i < outLen; j++) {
36423642
signed char c;
36433643
out[i] = key->data[j];
36443644
c = (signed char)ctMaskGTE((int)j, start);

0 commit comments

Comments
 (0)