diff options
author | Thomas Haller <thaller@redhat.com> | 2022-04-22 16:34:26 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-04-22 17:04:19 (GMT) |
commit | aa398b5fdaa27678069ea7b4a322b14281075db4 (patch) | |
tree | 6251b4674590ef160cdd1d92b0a5cd9c1b8e4337 | |
parent | 40683cc496b2aaae0b2ca53329b092a9a77fc82b (diff) | |
download | libnl-aa398b5fdaa27678069ea7b4a322b14281075db4.zip libnl-aa398b5fdaa27678069ea7b4a322b14281075db4.tar.gz libnl-aa398b5fdaa27678069ea7b4a322b14281075db4.tar.bz2 |
route/ip6vti,ip6gre: fix printing invalid data in ip6{vti,gre}_dump_details()
Coverity doesn't like this:
libnl-3.6.0/lib/route/link/ip6vti.c:209: invalid_type: Argument "ip6vti->remote" to format specifier "%#x" was expected to have type "unsigned int" but has type "struct in6_addr".
libnl-3.6.0/lib/route/link/ip6vti.c:201: invalid_type: Argument "ip6vti->local" to format specifier "%#x" was expected to have type "unsigned int" but has type "struct in6_addr".
libnl-3.6.0/lib/route/link/ip6gre.c:285: invalid_type: Argument "ip6gre->remote" to format specifier "%#x" was expected to have type "unsigned int" but has type "struct in6_addr".
libnl-3.6.0/lib/route/link/ip6gre.c:277: invalid_type: Argument "ip6gre->local" to format specifier "%#x" was expected to have type "unsigned int" but has type "struct in6_addr".
Coverity is right. But in practice, this code was unreachable
because there is no scenario when inet_ntop() will fail.
-rw-r--r-- | lib/route/link/ip6gre.c | 15 | ||||
-rw-r--r-- | lib/route/link/ip6vti.c | 15 |
2 files changed, 12 insertions, 18 deletions
diff --git a/lib/route/link/ip6gre.c b/lib/route/link/ip6gre.c index 8583a01..5d5c3a0 100644 --- a/lib/route/link/ip6gre.c +++ b/lib/route/link/ip6gre.c @@ -238,7 +238,8 @@ static void ip6gre_dump_line(struct rtnl_link *link, struct nl_dump_params *p) static void ip6gre_dump_details(struct rtnl_link *link, struct nl_dump_params *p) { struct ip6gre_info *ip6gre = link->l_info; - char *name, addr[INET6_ADDRSTRLEN]; + char *name; + char addr[INET6_ADDRSTRLEN]; if (ip6gre->ip6gre_mask & IP6GRE_ATTR_LINK) { nl_dump(p, " link "); @@ -271,18 +272,14 @@ static void ip6gre_dump_details(struct rtnl_link *link, struct nl_dump_params *p if (ip6gre->ip6gre_mask & IP6GRE_ATTR_LOCAL) { nl_dump(p, " local "); - if(inet_ntop(AF_INET6, &ip6gre->local, addr, sizeof(addr))) - nl_dump_line(p, "%s\n", addr); - else - nl_dump_line(p, "%#x\n", ip6gre->local); + nl_dump_line(p, "%s\n", + _nl_inet_ntop(AF_INET6, &ip6gre->local, addr)); } if (ip6gre->ip6gre_mask & IP6GRE_ATTR_REMOTE) { nl_dump(p, " remote "); - if(inet_ntop(AF_INET6, &ip6gre->remote, addr, sizeof(addr))) - nl_dump_line(p, "%s\n", addr); - else - nl_dump_line(p, "%#x\n", ip6gre->remote); + nl_dump_line(p, "%s\n", + _nl_inet_ntop(AF_INET6, &ip6gre->remote, addr)); } if (ip6gre->ip6gre_mask & IP6GRE_ATTR_TTL) { diff --git a/lib/route/link/ip6vti.c b/lib/route/link/ip6vti.c index 0afaf7a..8c603ab 100644 --- a/lib/route/link/ip6vti.c +++ b/lib/route/link/ip6vti.c @@ -172,7 +172,8 @@ static void ip6vti_dump_line(struct rtnl_link *link, struct nl_dump_params *p) static void ip6vti_dump_details(struct rtnl_link *link, struct nl_dump_params *p) { struct ip6vti_info *ip6vti = link->l_info; - char *name, addr[INET6_ADDRSTRLEN]; + char *name; + char addr[INET6_ADDRSTRLEN]; if (ip6vti->ip6vti_mask & IP6VTI_ATTR_LINK) { nl_dump(p, " link "); @@ -195,18 +196,14 @@ static void ip6vti_dump_details(struct rtnl_link *link, struct nl_dump_params *p if (ip6vti->ip6vti_mask & IP6VTI_ATTR_LOCAL) { nl_dump(p, " local "); - if(inet_ntop(AF_INET6, &ip6vti->local, addr, sizeof(addr))) - nl_dump_line(p, "%s\n", addr); - else - nl_dump_line(p, "%#x\n", ip6vti->local); + nl_dump_line(p, "%s\n", + _nl_inet_ntop(AF_INET6, &ip6vti->local, addr)); } if (ip6vti->ip6vti_mask & IP6VTI_ATTR_REMOTE) { nl_dump(p, " remote "); - if(inet_ntop(AF_INET6, &ip6vti->remote, addr, sizeof(addr))) - nl_dump_line(p, "%s\n", addr); - else - nl_dump_line(p, "%#x\n", ip6vti->remote); + nl_dump_line(p, "%s\n", + _nl_inet_ntop(AF_INET6, &ip6vti->remote, addr)); } if (ip6vti->ip6vti_mask & IP6VTI_ATTR_FWMARK) { |