nss: Keep thread-local h_errno in sync in get*_r functions

Message ID 20170809152720.3809C4029813A@oldenburg.str.redhat.com
State New
Headers show

Commit Message

Florian Weimer Aug. 9, 2017, 3:27 p.m.
2017-08-09  Florian Weimer  <fweimer@redhat.com>

	* nss/getXXbyYY_r.c (REENTRANT_NAME): Keep h_errno and *h_errnop
	in sync.

Patch

diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
index 6c547ea..5e3bead 100644
--- a/nss/getXXbyYY_r.c
+++ b/nss/getXXbyYY_r.c
@@ -219,6 +219,7 @@  INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
   if (res_ctx == NULL)
     {
       *h_errnop = NETDB_INTERNAL;
+      __set_h_errno (NETDB_INTERNAL);
       *result = NULL;
       return errno;
     }
@@ -394,6 +395,12 @@  done:
   else if (status != NSS_STATUS_SUCCESS && !any_service)
     /* We were not able to use any service.  */
     *h_errnop = NO_RECOVERY;
+
+  /* If an *_r function is called by an application, the h_errnop
+     parameter could be distinct from the h_errno variable.  Keep both
+     in sync.  This can result in a harmless self-assignment of the
+     h_errno variable.  */
+  __set_h_errno (*h_errnop);
 #endif
 #ifdef POSTPROCESS
   POSTPROCESS;