summaryrefslogtreecommitdiff
path: root/src/nss-myhostname
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-02-04 15:56:26 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-02-07 01:02:33 -0500
commitd2f1f23ad2636cf05589a67b5229c7fd604bc21f (patch)
tree96d3821b0e03230b6797b7c8cf5665e62df2cb9d /src/nss-myhostname
parent13219b7f74cb2722746b953bbec7593d5cc665e3 (diff)
downloadsystemd-d2f1f23ad2636cf05589a67b5229c7fd604bc21f.tar.gz
nss-myhostname: copy first result to preallocated buffer
Fixes a segfault in nscd when using nss-myhostname. Nscd expects that an NSS module's gethostbyname4_r function returns its first result in the pre-allocated gaih_addrtuple denoted by **pat. (See nscd/aicache.c in the Glibc sources.) However, nss-myhostname doesn't fill in **pat but allocates the first result in ‘buffer’, then sets *pat. So nscd crashes (e.g. when running ‘getent ahosts my-machine’). Hard to tell if this is a bug in nscd, since there doesn't seem to be a proper API spec for gethostbyname4_r. But in any case, this patch fixes the crash by copying the first result to **pat.
Diffstat (limited to 'src/nss-myhostname')
-rw-r--r--src/nss-myhostname/nss-myhostname.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 834a80690f..b0fb8323ad 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -176,7 +176,11 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
/* Verify the size matches */
assert(idx == ms);
- *pat = r_tuple_prev;
+ /* Nscd expects us to store the first record in **pat. */
+ if (*pat)
+ **pat = *r_tuple_prev;
+ else
+ *pat = r_tuple_prev;
if (ttlp)
*ttlp = 0;