Skip to content

Commit c880fcf

Browse files
add check on padSz return, coverity issue 394711
1 parent 25d52dd commit c880fcf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

wolfcrypt/src/pkcs7.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8634,6 +8634,8 @@ int wc_PKCS7_PadData(byte* in, word32 inSz, byte* out, word32 outSz,
86348634
return BAD_FUNC_ARG;
86358635

86368636
padSz = wc_PKCS7_GetPadSize(inSz, blockSz);
8637+
if (padSz < 0)
8638+
return padSz;
86378639

86388640
if (outSz < (inSz + padSz))
86398641
return BAD_FUNC_ARG;

wolfcrypt/test/test.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49471,6 +49471,11 @@ static wc_test_ret_t pkcs7signed_run_vectors(
4947149471

4947249472
XMEMSET(out, 0, outSz);
4947349473

49474+
/* test inner pad size error with block size being 0 */
49475+
ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
49476+
if (ret > 0)
49477+
ERROR_OUT(-1, out);
49478+
4947449479
ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
4947549480
if (ret < 0)
4947649481
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);

0 commit comments

Comments
 (0)