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 <tascad@altlinux.org>
Signed-off-by: Egor Mikhailov <mikhailovev@sgu.ru>
This commit is contained in:
mikhailofff
2026-06-18 09:05:29 +04:00
committed by Nico Williams
parent 9df6b9e13a
commit afc4c486a1
+3 -1
View File
@@ -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;