From e065c4f8ef82982e3d94e62bece0e871a52ff839 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 14 Dec 2023 13:02:30 -0500 Subject: [PATCH] fix use after free --- libtel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libtel.c b/libtel.c index 29e3779..fc18573 100644 --- a/libtel.c +++ b/libtel.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -54,8 +55,9 @@ int tel_get_addr(char *ip, char *port, struct sockaddr **addr, socklen_t *addr_l int res = getaddrinfo(ip, port, &hints, &info); if(res != 0) return res; - *addr = info->ai_addr; + *addr = malloc(info->ai_addrlen); *addr_len = info->ai_addrlen; + memcpy(*addr, info->ai_addr, info->ai_addrlen); freeaddrinfo(info); return 0;