inet_pton: help ASan find the underflow

The generated unit tests have the input parameters in large stack
buffers and therefore ASan doesn't notice under or overflows in them.
Copy the input parameter into a locally allocated buffer to trigger ASan
if something goes wrong.

Signed-off-by: Janos Follath <[email protected]>
This commit is contained in:
Janos Follath
2026-01-20 18:19:33 +00:00
parent be0cef43ea
commit 763a0cfd15
+11 -1
View File
@@ -482,12 +482,22 @@ exit:
void x509_crt_parse_cn_inet_pton(const char *cn, data_t *exp, int ref_ret)
{
uint32_t addr[4];
size_t addrlen = mbedtls_x509_crt_parse_cn_inet_pton(cn, addr);
char *cn_local = NULL;
size_t cn_local_len = strlen(cn) + 1;
TEST_CALLOC(cn_local, cn_local_len);
memcpy(cn_local, cn, cn_local_len);
size_t addrlen = mbedtls_x509_crt_parse_cn_inet_pton(cn_local, addr);
TEST_EQUAL(addrlen, (size_t) ref_ret);
if (addrlen) {
TEST_MEMORY_COMPARE(exp->x, exp->len, addr, addrlen);
}
exit:
mbedtls_free(cn_local);
}
/* END_CASE */