nss: Keep thread-local h_errno in sync in get*_r functions
Commit Message
2017-08-09 Florian Weimer <fweimer@redhat.com>
* nss/getXXbyYY_r.c (REENTRANT_NAME): Keep h_errno and *h_errnop
in sync.
@@ -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;