Skip to contentSkip to conversation

unit: fix memory leak in test-dpp

PATCH In review James Prestwood 2 participants 3 messages Feb 27, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 unit: fix memory leak in test-dpp

---
 unit/test-dpp.c | 2 ++
 1 file changed, 2 insertions(+)
unit/test-dpp.c +2 -0
index 781d494a..0a4fd01f 100644
@@ -331,8 +331,10 @@ static void test_key_derivation(const void *data)
 
 	if (vector->i_asn1) {
 		HEX2BUF(vector->i_asn1, tmp, sizeof(tmp));
+		l_free(asn1);
 		asn1 = dpp_point_to_asn1(i_boot_public, &asn1_len);
 
+		l_free(from_asn1);
 		from_asn1 = dpp_point_from_asn1(asn1, asn1_len);
 
 		assert(l_ecc_points_are_equal(from_asn1, i_boot_public));
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 crypto: fix uninitialized variable coverity warning

For some encrypt operations DPP passes no AD iovecs (both are NULL/0). But since the iovec itself is on the stack 'ad' is a valid pointer from within aes_siv_encrypt. This causes memcpy to be called which coverity complains about. Since the copy length is zero it was effectively a no-op, but check num_ad to prevent the call.

---
 src/crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/crypto.c +1 -1
index 3128b2a5..7235e3c2 100644
@@ -331,7 +331,7 @@ bool aes_siv_encrypt(const void *key, size_t key_len, const void *in,
 	struct iovec iov[num_ad + 1];
 	uint8_t v[16];
 
-	if (ad)
+	if (ad && num_ad)
 		memcpy(iov, ad, sizeof(struct iovec) * num_ad);
 
 	iov[num_ad].iov_base = (void *)in;
Signature · 1 line
2.34.1