From d2f4a9488ce0847da754614706fadefbca9ed2a4 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 24 Mar 2021 14:45:02 +0100 Subject: [PATCH] local-addresses: fix use of uninitialized value This can happen if ifi fails to be read from the netlink message and the error is ENODATA. Fixes the following valgrind message when running netstat: ==164141== Conditional jump or move depends on uninitialised value(s) ==164141== at 0x524AE60: address_compare (local-addresses.c:29) ==164141== by 0x48BCC78: msort_with_tmp.part.0 (msort.c:105) ==164141== by 0x48BC9E4: msort_with_tmp (msort.c:45) ==164141== by 0x48BC9E4: msort_with_tmp.part.0 (msort.c:53) ==164141== by 0x48BCF85: msort_with_tmp (msort.c:45) ==164141== by 0x48BCF85: qsort_r (msort.c:297) ==164141== by 0x52500FC: UnknownInlinedFun (sort-util.h:47) ==164141== by 0x52500FC: local_gateways.constprop.0 (local-addresses.c:310) ==164141== by 0x5251C05: _nss_myhostname_gethostbyaddr2_r (nss-myhostname.c:456) ==164141== by 0x5252006: _nss_myhostname_gethostbyaddr_r (nss-myhostname.c:500) ==164141== by 0x498E7FE: gethostbyaddr_r@@GLIBC_2.2.5 (getXXbyYY_r.c:274) ==164141== by 0x498E560: gethostbyaddr (getXXbyYY.c:135) ==164141== by 0x121353: INET_rresolve.constprop.0 (inet.c:212) ==164141== by 0x1135B9: INET_sprint (inet.c:261) ==164141== by 0x121BFC: addr_do_one.constprop.0.isra.0 (netstat.c:1156) --- src/shared/local-addresses.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/local-addresses.c b/src/shared/local-addresses.c index 2c860f76d5d..1de890f1421 100644 --- a/src/shared/local-addresses.c +++ b/src/shared/local-addresses.c @@ -204,7 +204,7 @@ int local_gateways(sd_netlink *context, int ifindex, int af, struct local_addres union in_addr_union gateway; uint16_t type; unsigned char dst_len, src_len, table; - uint32_t ifi, metric = 0; + uint32_t ifi = 0, metric = 0; size_t rta_len; int family; RouteVia via; -- 2.47.3