diff --git a/wolfcrypt/src/coding.c b/wolfcrypt/src/coding.c index 6347361ce4..e2ac7d3377 100644 --- a/wolfcrypt/src/coding.c +++ b/wolfcrypt/src/coding.c @@ -174,6 +174,9 @@ int Base64_Decode_nonCT(const byte* in, word32 inLen, byte* out, word32* outLen) int ret; const byte maxIdx = BASE64DECODE_TABLE_SZ + BASE64_MIN - 1; + if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL) + return BAD_FUNC_ARG; + while (inLen > 3) { int pad3 = 0; int pad4 = 0; @@ -273,6 +276,9 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen) word32 j = 0; int ret; + if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL) + return BAD_FUNC_ARG; + while (inLen > 3) { int pad3 = 0; int pad4 = 0; @@ -474,6 +480,9 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out, word32 outSz = (inLen + 3 - 1) / 3 * 4; word32 addSz = (outSz + BASE64_LINE_SZ - 1) / BASE64_LINE_SZ; /* new lines */ + if (in == NULL && inLen > 0) + return BAD_FUNC_ARG; + if (escaped == WC_ESC_NL_ENC) addSz *= 3; /* instead of just \n, we're doing %0A triplet */ else if (escaped == WC_NO_NL_ENC)