Skip to content

Commit 7b31aca

Browse files
committed
guard zero length in DES ncbc
1 parent 75bbcca commit 7b31aca

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/ssl_crypto.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,11 +2722,19 @@ void wolfSSL_DES_ncbc_encrypt(const unsigned char* input, unsigned char* output,
27222722
int enc)
27232723
{
27242724
unsigned char tmp[DES_IV_SIZE];
2725-
/* Calculate length to a multiple of block size. */
2726-
size_t offset = (size_t)length;
2725+
size_t offset;
27272726

27282727
WOLFSSL_ENTER("wolfSSL_DES_ncbc_encrypt");
27292728

2729+
/* Zero/negative length: no block to derive an IV from. The offset math
2730+
* below would underflow for length == 0, yielding a wild-pointer read. */
2731+
if (length <= 0) {
2732+
WOLFSSL_LEAVE("wolfSSL_DES_ncbc_encrypt", 0);
2733+
return;
2734+
}
2735+
2736+
/* Calculate length to a multiple of block size. */
2737+
offset = (size_t)length;
27302738
offset = (offset + DES_BLOCK_SIZE - 1) / DES_BLOCK_SIZE;
27312739
offset *= DES_BLOCK_SIZE;
27322740
offset -= DES_BLOCK_SIZE;

0 commit comments

Comments
 (0)