Skip to content

Commit 362eda5

Browse files
committed
add NULL checks to Base64 encode/decode
1 parent 1dddc1d commit 362eda5

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

wolfcrypt/src/coding.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ int Base64_Decode_nonCT(const byte* in, word32 inLen, byte* out, word32* outLen)
174174
int ret;
175175
const byte maxIdx = BASE64DECODE_TABLE_SZ + BASE64_MIN - 1;
176176

177+
if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL)
178+
return BAD_FUNC_ARG;
179+
177180
while (inLen > 3) {
178181
int pad3 = 0;
179182
int pad4 = 0;
@@ -273,6 +276,9 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
273276
word32 j = 0;
274277
int ret;
275278

279+
if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL)
280+
return BAD_FUNC_ARG;
281+
276282
while (inLen > 3) {
277283
int pad3 = 0;
278284
int pad4 = 0;
@@ -474,6 +480,9 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out,
474480
word32 outSz = (inLen + 3 - 1) / 3 * 4;
475481
word32 addSz = (outSz + BASE64_LINE_SZ - 1) / BASE64_LINE_SZ; /* new lines */
476482

483+
if (in == NULL && inLen > 0)
484+
return BAD_FUNC_ARG;
485+
477486
if (escaped == WC_ESC_NL_ENC)
478487
addSz *= 3; /* instead of just \n, we're doing %0A triplet */
479488
else if (escaped == WC_NO_NL_ENC)

0 commit comments

Comments
 (0)