fixes for null derefs in native Dilithium and Kyber implementations, detected by unit.test and cppcheck.

This commit is contained in:
Daniel Pouzzner
2024-07-19 14:35:39 -05:00
parent 0aa0f26289
commit e13a8ddcfb
2 changed files with 9 additions and 3 deletions

View File

@ -7421,7 +7421,9 @@ int wc_dilithium_check_key(dilithium_key* key)
}
/* Dispose of allocated memory. */
XFREE(s1, key->heap, DYNAMIC_TYPE_DILITHIUM);
if (s1 != NULL) {
XFREE(s1, key->heap, DYNAMIC_TYPE_DILITHIUM);
}
#else
/* Validate parameter. */
if (key == NULL) {

View File

@ -286,7 +286,9 @@ int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
}
/* Free dynamic memory allocated in function. */
XFREE(a, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (a != NULL) {
XFREE(a, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;
}
@ -890,7 +892,9 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
#ifndef USE_INTEL_SPEEDUP
/* Dispose of dynamic memory allocated in function. */
XFREE(cmp, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (cmp != NULL) {
XFREE(cmp, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
}
#endif
return ret;