Fix leak in getaddrinfo introduced by the fix for CVE-2023-4806 [BZ #30843]

This patch fixes a very recently added leak in getaddrinfo.

This was assigned CVE-2023-5156.

Resolves: BZ #30884
Related: BZ #30842

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit ec6b95c330)
This commit is contained in:
Romain Geissler 2023-09-25 01:21:51 +01:00 committed by Siddhesh Poyarekar
parent e09ee267c0
commit 8006457ab7
3 changed files with 24 additions and 3 deletions

View File

@ -147,6 +147,15 @@ endif
extra-test-objs += nss_test1.os nss_test2.os nss_test_errno.os \
nss_test_gai_hv2_canonname.os
ifeq ($(run-built-tests),yes)
ifneq (no,$(PERL))
tests-special += $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out
endif
endif
generated += mtrace-tst-nss-gai-hv2-canonname.out \
tst-nss-gai-hv2-canonname.mtrace
include ../Rules
ifeq (yes,$(have-selinux))
@ -214,3 +223,14 @@ endif
$(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
$(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
tst-nss-gai-hv2-canonname-ENV = \
MALLOC_TRACE=$(objpfx)tst-nss-gai-hv2-canonname.mtrace \
LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
$(objpfx)mtrace-tst-nss-gai-hv2-canonname.out: \
$(objpfx)tst-nss-gai-hv2-canonname.out
{ test -r $(objpfx)tst-nss-gai-hv2-canonname.mtrace \
|| ( echo "tst-nss-gai-hv2-canonname.mtrace does not exist"; exit 77; ) \
&& $(common-objpfx)malloc/mtrace \
$(objpfx)tst-nss-gai-hv2-canonname.mtrace; } > $@; \
$(evaluate-test)

View File

@ -21,6 +21,7 @@
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <mcheck.h>
#include <support/check.h>
#include <support/xstdio.h>
#include "nss/tst-nss-gai-hv2-canonname.h"
@ -41,6 +42,8 @@ static void do_prepare (int a, char **av)
static int
do_test (void)
{
mtrace ();
__nss_configure_lookup ("hosts", "test_gai_hv2_canonname");
struct addrinfo hints = {};

View File

@ -1196,9 +1196,7 @@ free_and_return:
if (malloc_name)
free ((char *) name);
free (addrmem);
if (res.free_at)
free (res.at);
free (res.canon);
gaih_result_reset (&res);
return result;
}