summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaveen Kumar Chaudhary <[email protected]>2026-07-10 20:51:33 +0530
committerJerome Forissier <[email protected]>2026-07-23 17:05:20 +0200
commit495368c5538303c3026eb32afd6f7027fbc88a0e (patch)
tree9796a53a04077ddce28e535857696a63bf4c4869
parent2e7e0dbb1594bcb909d369be92a951b17e511a31 (diff)
cmd: lwip: wget: free mbedtls x509 cert context to avoid memory leak
_set_cacert() calls mbedtls_x509_crt_init(&crt) followed by mbedtls_x509_crt_parse(), which allocates internal storage (parsed cert fields, chain links, raw buffers) inside the crt object. The function then returns on both the error and success paths without calling mbedtls_x509_crt_free(&crt), so all of that internal state is leaked when the stack-allocated crt goes out of scope. Every invocation of "wget cacert ..." leaks memory. Free the cert object on both return paths. Signed-off-by: Naveen Kumar Chaudhary <[email protected]> Reviewed-by: Jerome Forissier <[email protected]>
-rw-r--r--cmd/lwip/wget.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/cmd/lwip/wget.c b/cmd/lwip/wget.c
index 4883ad61bce..531e886e986 100644
--- a/cmd/lwip/wget.c
+++ b/cmd/lwip/wget.c
@@ -67,12 +67,15 @@ static int _set_cacert(const void *addr, size_t sz)
if (ret) {
if (!wget_info->silent)
printf("Could not parse certificates (%d)\n", ret);
+ mbedtls_x509_crt_free(&crt);
free(cacert);
cacert = NULL;
cacert_size = 0;
return CMD_RET_FAILURE;
}
+ mbedtls_x509_crt_free(&crt);
+
#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
cacert_initialized = true;
#endif