From: Karel Zak Date: Wed, 27 Mar 2013 13:33:17 +0000 (+0100) Subject: agetty: make \{4,6} issue file code more robust [coverity scan] X-Git-Tag: v2.23-rc2~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=915c1d99f60d81278726e6f4441a80da755c4227;p=thirdparty%2Futil-linux.git agetty: make \{4,6} issue file code more robust [coverity scan] ... and more readable for static analyzers Signed-off-by: Karel Zak --- diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 3c6307a216..7ac12f2014 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -1781,7 +1781,6 @@ static void output_ip(sa_family_t family) if (host && getaddrinfo(host, NULL, &hints, &info) == 0 && info) { void *addr = NULL; - char buff[INET6_ADDRSTRLEN + 1]; switch (info->ai_family) { case AF_INET: @@ -1791,8 +1790,12 @@ static void output_ip(sa_family_t family) addr = &((struct sockaddr_in6 *) info->ai_addr)->sin6_addr; break; } - inet_ntop(info->ai_family, (void *) addr, buff, sizeof(buff)); - printf("%s", buff); + if (addr) { + char buff[INET6_ADDRSTRLEN + 1]; + + inet_ntop(info->ai_family, (void *) addr, buff, sizeof(buff)); + printf("%s", buff); + } freeaddrinfo(info); }