Skip to content

Commit 6596419

Browse files
committed
add NULL validation to wolfCrypt APIs
1 parent fa9f24f commit 6596419

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

wolfcrypt/src/camellia.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ int wc_CamelliaSetKey(wc_Camellia* cam, const byte* key, word32 len, const byte*
15211521
{
15221522
int ret = 0;
15231523

1524-
if (cam == NULL) return BAD_FUNC_ARG;
1524+
if (cam == NULL || key == NULL) return BAD_FUNC_ARG;
15251525

15261526
XMEMSET(cam->key, 0, WC_CAMELLIA_TABLE_BYTE_LEN);
15271527

wolfcrypt/src/compress.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ int wc_Compress_ex(byte* out, word32 outSz, const byte* in, word32 inSz,
8181
z_stream stream;
8282
int result = 0;
8383

84+
if (out == NULL || in == NULL)
85+
return BAD_FUNC_ARG;
86+
8487
stream.next_in = (Bytef*)in;
8588
stream.avail_in = (uInt)inSz;
8689
#ifdef MAXSEG_64K
@@ -149,6 +152,9 @@ int wc_DeCompress_ex(byte* out, word32 outSz, const byte* in, word32 inSz,
149152
z_stream stream;
150153
int result = 0;
151154

155+
if (out == NULL || in == NULL)
156+
return BAD_FUNC_ARG;
157+
152158
stream.next_in = (Bytef*)in;
153159
stream.avail_in = (uInt)inSz;
154160
/* Check for source > 64K on 16-bit machine: */

wolfcrypt/src/hmac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ int wc_HmacInit_Id(Hmac* hmac, unsigned char* id, int len, void* heap,
13951395

13961396
if (ret == 0)
13971397
ret = wc_HmacInit(hmac, heap, devId);
1398-
if (ret == 0) {
1398+
if (ret == 0 && id != NULL && len != 0) {
13991399
XMEMCPY(hmac->id, id, (size_t)len);
14001400
hmac->idLen = len;
14011401
}

wolfcrypt/src/wc_lms.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,8 @@ int wc_LmsKey_ExportPubRaw(const LmsKey* key, byte* out, word32* outLen)
11591159
int ret = 0;
11601160

11611161
/* Validate parameters. */
1162-
if ((key == NULL) || (out == NULL) || (outLen == NULL)) {
1162+
if ((key == NULL) || (out == NULL) || (outLen == NULL) ||
1163+
(key->params == NULL)) {
11631164
ret = BAD_FUNC_ARG;
11641165
}
11651166
/* Check size of out is sufficient. */

0 commit comments

Comments
 (0)