From 7b0e3de9fe4a6eb3d82c794f85389cd258114ddc Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 23 Nov 2025 05:09:59 +0000 Subject: [PATCH] avahi-test: do reverse lookups only when the corresponding lookups succeed Fixes ``` + valgrind --track-origins=yes --exit-on-first-error=yes --error-exitcode=1 --leak-check=full --track-fds=yes /tmp/tmp.4MDJpCvVh1/avahi-test ipv6.local ==62957== Memcheck, a memory error detector ==62957== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==62957== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==62957== Command: /tmp/tmp.4MDJpCvVh1/avahi-test ipv6.local ==62957== ==62957== Use of uninitialised value of size 8 ==62957== at 0x48C60BB: _itoa_word (_itoa.c:183) ==62957== by 0x48D0C9B: __printf_buffer (vfprintf-process-arg.c:155) ==62957== by 0x48EF991: __vsprintf_internal (iovsprintf.c:62) ==62957== by 0x499EE9E: __sprintf_chk (sprintf_chk.c:40) ==62957== by 0x49AACA9: sprintf (stdio2.h:30) ==62957== by 0x49AACA9: inet_ntop4 (inet_ntop.c:85) ==62957== by 0x49AACA9: inet_ntop (inet_ntop.c:57) ==62957== by 0x10A91F: avahi_resolve_address_with_socket (avahi.c:138) ==62957== by 0x10AB11: avahi_resolve_address (avahi.c:181) ==62957== by 0x10B85F: main (avahi-test.c:38) ==62957== Uninitialised value was created by a stack allocation ==62957== at 0x10B780: main (avahi-test.c:26) ==62957== ==62957== ==62957== Exit program on first error (--exit-on-first-error=yes) ``` Closes https://github.com/avahi/nss-mdns/issues/104 --- src/avahi-test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/avahi-test.c b/src/avahi-test.c index 7074a86..0b5e0bf 100644 --- a/src/avahi-test.c +++ b/src/avahi-test.c @@ -29,17 +29,17 @@ int main(int argc, char* argv[]) { int r; if ((r = avahi_resolve_name(AF_INET, argc >= 2 ? argv[1] : "cocaine.local", - &result)) == 0) + &result)) == 0) { printf("AF_INET: %s\n", inet_ntop(AF_INET, &(result.address.ipv4), t, sizeof(t))); - else - printf("AF_INET: failed (%i).\n", r); - if ((r = avahi_resolve_address(AF_INET, &(result.address.ipv4), t, - sizeof(t))) == 0) - printf("REVERSE: %s\n", t); - else - printf("REVERSE: failed (%i).\n", r); + if ((r = avahi_resolve_address(AF_INET, &(result.address.ipv4), t, + sizeof(t))) == 0) + printf("REVERSE: %s\n", t); + else + printf("REVERSE: failed (%i).\n", r); + } else + printf("AF_INET: failed (%i).\n", r); if ((r = avahi_resolve_name(AF_INET6, argc >= 2 ? argv[1] : "cocaine.local", &result)) == 0)