From a4662254135ddf6ad3fb84701a6ac6196cec35c9 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Tue, 18 Jun 2013 17:02:42 +0000 Subject: Don't use inet_ntoa() twice in one parameter list. You'll just print one of the strings twice. Spotted by mpi@, who also tweaked the diff by pointing out INET_ADDRSTRLEN. Should fix mysterious messages like "1.2.3.4, not 1.2.3.4, deleted from ...". --- sbin/dhclient/dhclient.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'sbin/dhclient') diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 38e5c3e328a..773c7668c67 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.256 2013/06/18 00:30:39 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.257 2013/06/18 17:02:41 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -176,6 +176,7 @@ get_ifa(char *cp, int n) void routehandler(void) { + char ntoabuf[INET_ADDRSTRLEN]; struct in_addr a, b; ssize_t n; int linkstat, rslt; @@ -236,11 +237,11 @@ routehandler(void) if ((client->flags & IS_RESPONSIBLE) == 0) /* We're not responsible yet! */ break; - if (adding.s_addr != INADDR_ANY) - rslt = asprintf(&errmsg, "%s, not %s, added " - "to %s", inet_ntoa(a), inet_ntoa(adding), - ifi->name); - else + if (adding.s_addr != INADDR_ANY) { + strlcpy(ntoabuf, inet_ntoa(a), sizeof(ntoabuf)); + rslt = asprintf(&errmsg, "%s, not %s, added to %s", + ntoabuf, inet_ntoa(adding), ifi->name); + } else rslt = asprintf(&errmsg, "%s added to %s", inet_ntoa(a), ifi->name); goto die; @@ -283,11 +284,11 @@ routehandler(void) quit = INTERNALSIG; break; } - if (deleting.s_addr != INADDR_ANY) - rslt = asprintf(&errmsg, "%s, not %s, deleted " - "from %s", inet_ntoa(a), - inet_ntoa(deleting), ifi->name); - else + if (deleting.s_addr != INADDR_ANY) { + strlcpy(ntoabuf, inet_ntoa(a), sizeof(ntoabuf)); + rslt = asprintf(&errmsg, "%s, not %s, deleted from %s", + ntoabuf, inet_ntoa(deleting), ifi->name); + } else rslt = asprintf(&errmsg, "%s deleted from %s", inet_ntoa(a), ifi->name); goto die; -- cgit v1.2.3