]> git.ipfire.org Git - thirdparty/libvirt.git/commit
libvirt_nss: Allocate buffer in aiforaf() dynamically
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 21 May 2025 16:14:51 +0000 (18:14 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 May 2025 13:44:12 +0000 (15:44 +0200)
commit481a38c45fbe72963dcf9f0f411c6d6df5c3cd68
tree9dcc597779af9c90c4ab2a6a3585b0dfb082c6f1
parent209ca5f83995b1624a479449515352bd2e959d51
libvirt_nss: Allocate buffer in aiforaf() dynamically

While we were trying to decrease stack usage of some functions,
in v9.8.0-rc1~217 we introduced a couple of internal blocks to
the aiforaf() and declared some variables inside those blocks
hoping the compiler will reuse the stack for each block. While in
general this might be a good strategy, specifically in case of
NSS_NAME(gethostbyname2) this is a terrible thing to do.

Problem is, NSS_NAME(gethostbyname2) is given a caller allocated
buffer and an address of a pointer where the resolved address is
stored. And you've probably guessed it already: upon successful
return, the pointer is set to point somewhere inside the buffer.

Now, if the buffer doesn't live long enough, which in our case it
does not (since it was left in the previous block), we should
refrain from dereferencing the resolved pointer.

Just allocate the buffer on the heap.

Fixes: 9e5f2fe4021ada74adbe34ca03be60812c91f334
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
tools/nss/libvirt_nss.c