This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] nss: Keep thread-local h_errno in sync in get*_r functions
- From: fweimer at redhat dot com (Florian Weimer)
- To: libc-alpha at sourceware dot org
- Date: Wed, 09 Aug 2017 17:27:20 +0200
- Subject: [PATCH] nss: Keep thread-local h_errno in sync in get*_r functions
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1C9FF25536C
2017-08-09 Florian Weimer <fweimer@redhat.com>
* nss/getXXbyYY_r.c (REENTRANT_NAME): Keep h_errno and *h_errnop
in sync.
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;