From afc4c486a13c8e22486688d5ae1cfeeeaccbb37e Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Thu, 18 Jun 2026 09:05:29 +0400 Subject: [PATCH] lib/asn1: fix USE_AFTER_FREE in der_print_hex_heim_integer Set *p to NULL on asprintf failure to prevent a dangling pointer and subsequent USE_AFTER_FREE when the caller ignores ENOMEM. Pair-Programmed-With: Dmitry Mikhalchenko Signed-off-by: Egor Mikhailov --- lib/asn1/der_format.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/asn1/der_format.c b/lib/asn1/der_format.c index bb4a7cee9..3b6fae676 100644 --- a/lib/asn1/der_format.c +++ b/lib/asn1/der_format.c @@ -97,8 +97,10 @@ der_print_hex_heim_integer (const heim_integer *data, char **p) if (data->negative) { len = asprintf(&q, "-%s", *p); free(*p); - if (len < 0) + if (len < 0) { + *p = NULL; return ENOMEM; + } *p = q; } return 0;