]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2944] errno is not preserved properly in ntpdate after sendto call.
authorJuergen Perlinger <perlinger@ntp.org>
Sat, 28 Nov 2015 21:59:39 +0000 (22:59 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sat, 28 Nov 2015 21:59:39 +0000 (22:59 +0100)
 - applied patch by Christos Zoulas.

bk: 565a23cbU86DDMCJHHyPeYYB7hZ1Pg

ChangeLog
libntp/socktohost.c

index a787d4306b28c0d33452f9df3df4f4183874717b..613c9b0d86e393346e53c3eb4d9fea3e8b7d28ef 100644 (file)
--- 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
index 3d9ab960e8a1fd2a7c6a31f312f2cea3107a7302..fdf9adb9e2e6925335d9e23c186c7e5659c54272 100644 (file)
@@ -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;
 }