From: Juergen Perlinger Date: Sat, 28 Nov 2015 21:59:39 +0000 (+0100) Subject: [Bug 2944] errno is not preserved properly in ntpdate after sendto call. X-Git-Tag: NTP_4_3_85~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed795ed12ca27e365de9a923b89a7aceb658f4b5;p=thirdparty%2Fntp.git [Bug 2944] errno is not preserved properly in ntpdate after sendto call. - applied patch by Christos Zoulas. bk: 565a23cbU86DDMCJHHyPeYYB7hZ1Pg --- diff --git a/ChangeLog b/ChangeLog index a787d4306..613c9b0d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * CID 1339962: Explicitly initialize variable in caljulian test. HStenn. * [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn. * [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray +* [Bug 2944] errno is not preserved properly in ntpdate after sendto call. + - applied patch by Christos Zoulas. perlinger@ntp.org * [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault - fixed data race conditions in threaded DNS worker. perlinger@ntp.org - limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org diff --git a/libntp/socktohost.c b/libntp/socktohost.c index 3d9ab960e..fdf9adb9e 100644 --- a/libntp/socktohost.c +++ b/libntp/socktohost.c @@ -36,13 +36,18 @@ socktohost( sockaddr_u addr; size_t octets; int a_info; + int saved_errno; + + saved_errno = socket_errno(); /* reverse the address to purported DNS name */ LIB_GETBUF(pbuf); gni_flags = NI_DGRAM | NI_NAMEREQD; if (getnameinfo(&sock->sa, SOCKLEN(sock), pbuf, LIB_BUFLENGTH, - NULL, 0, gni_flags)) + NULL, 0, gni_flags)) { + errno = saved_errno; return stoa(sock); /* use address */ + } TRACE(1, ("%s reversed to %s\n", stoa(sock), pbuf)); @@ -97,8 +102,10 @@ socktohost( } freeaddrinfo(alist); - if (ai != NULL) + if (ai != NULL) { + errno = saved_errno; return pbuf; /* forward check passed */ + } forward_fail: TRACE(1, ("%s forward check lookup fail: %s\n", pbuf, @@ -106,5 +113,6 @@ socktohost( LIB_GETBUF(pliar); snprintf(pliar, LIB_BUFLENGTH, "%s (%s)", stoa(sock), pbuf); + errno = saved_errno; return pliar; }