diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-07-15 23:00:00 +0900 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-07-25 10:23:22 +0200 |
commit | 06202b9e659e5cc72aeecc5200155b7c012fccbc (patch) | |
tree | 7a22eef18632b21c764e1d446a21b8a3054f326b /src/nss-myhostname | |
parent | 8d455017eedfe7e67f7fa5db9939c35b9e4dcf60 (diff) | |
download | systemd-06202b9e659e5cc72aeecc5200155b7c012fccbc.tar.gz |
nss: do not modify errno when NSS_STATUS_NOTFOUND or NSS_STATUS_SUCCESS
This also adds PROTECT_ERRNO for all nss module functions.
C.f. glibc NSS documents https://www.gnu.org/software/libc/manual/html_node/NSS-Modules-Interface.html
and discussion in https://sourceware.org/bugzilla/show_bug.cgi?id=23410.
Fixes #9585.
Diffstat (limited to 'src/nss-myhostname')
-rw-r--r-- | src/nss-myhostname/nss-myhostname.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index f82ce59f2c..5abc0c91bf 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -45,6 +45,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r( char *r_name; unsigned n; + PROTECT_ERRNO; BLOCK_SIGNALS(NSS_SIGNALS_BLOCK); assert(name); @@ -64,7 +65,6 @@ enum nss_status _nss_myhostname_gethostbyname4_r( n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses); if (n_addresses <= 0) { - *errnop = ENOENT; *h_errnop = HOST_NOT_FOUND; return NSS_STATUS_NOTFOUND; } @@ -81,7 +81,6 @@ enum nss_status _nss_myhostname_gethostbyname4_r( /* We respond to our local host name, our hostname suffixed with a single dot. */ if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) { - *errnop = ENOENT; *h_errnop = HOST_NOT_FOUND; return NSS_STATUS_NOTFOUND; } @@ -157,8 +156,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r( if (ttlp) *ttlp = 0; - /* Explicitly reset all error variables */ - *errnop = 0; + /* Explicitly reset both *h_errnop and h_errno to work around + * https://bugzilla.redhat.com/show_bug.cgi?id=1125975 */ *h_errnop = NETDB_SUCCESS; h_errno = 0; @@ -286,8 +285,8 @@ static enum nss_status fill_in_hostent( if (canonp) *canonp = r_name; - /* Explicitly reset all error variables */ - *errnop = 0; + /* Explicitly reset both *h_errnop and h_errno to work around + * https://bugzilla.redhat.com/show_bug.cgi?id=1125975 */ *h_errnop = NETDB_SUCCESS; h_errno = 0; @@ -309,6 +308,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r( uint32_t local_address_ipv4 = 0; int n_addresses = 0; + PROTECT_ERRNO; BLOCK_SIGNALS(NSS_SIGNALS_BLOCK); assert(name); @@ -334,7 +334,6 @@ enum nss_status _nss_myhostname_gethostbyname3_r( n_addresses = local_gateways(NULL, 0, af, &addresses); if (n_addresses <= 0) { - *errnop = ENOENT; *h_errnop = HOST_NOT_FOUND; return NSS_STATUS_NOTFOUND; } @@ -350,7 +349,6 @@ enum nss_status _nss_myhostname_gethostbyname3_r( } if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) { - *errnop = ENOENT; *h_errnop = HOST_NOT_FOUND; return NSS_STATUS_NOTFOUND; } @@ -393,6 +391,7 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( bool additional_from_hostname = false; unsigned n; + PROTECT_ERRNO; BLOCK_SIGNALS(NSS_SIGNALS_BLOCK); assert(addr); @@ -455,7 +454,6 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( } } - *errnop = ENOENT; *h_errnop = HOST_NOT_FOUND; return NSS_STATUS_NOTFOUND; |