Add check for if length is <= 0 in wc_Arc4SetKey

This commit is contained in:
Carie Pointer
2019-11-08 14:54:39 -07:00
parent 1d02943658
commit a2cdb87067
2 changed files with 8 additions and 9 deletions

View File

@@ -11262,15 +11262,14 @@ static int test_wc_Arc4SetKey (void)
/* Test bad args. */
if (ret == 0) {
ret = wc_Arc4SetKey(NULL, (byte*)key, keyLen);
if (ret == BAD_FUNC_ARG) {
ret = wc_Arc4SetKey(&arc, NULL, keyLen);
}
if (ret == BAD_FUNC_ARG) {
/* Exits normally if keyLen is incorrect. */
ret = wc_Arc4SetKey(&arc, (byte*)key, 0);
} else {
if (ret == BAD_FUNC_ARG)
ret = wc_Arc4SetKey(&arc, NULL, keyLen); /* NULL key */
if (ret == BAD_FUNC_ARG)
ret = wc_Arc4SetKey(&arc, (byte*)key, 0); /* length == 0 */
if (ret == BAD_FUNC_ARG)
ret = WOLFSSL_ERROR_NONE;
else
ret = WOLFSSL_FATAL_ERROR;
}
} /* END test bad args. */
printf(resultFmt, ret == 0 ? passed : failed);

View File

@@ -38,7 +38,7 @@ int wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length)
word32 i;
word32 keyIndex = 0, stateIndex = 0;
if (arc4 == NULL || key == NULL) {
if (arc4 == NULL || key == NULL || length <= 0) {
return BAD_FUNC_ARG;
}