diff options
author | Andreas Schwab <schwab@suse.de> | 2013-06-10 14:39:09 +0200 |
---|---|---|
committer | Andreas Schwab <schwab@suse.de> | 2013-06-11 11:29:50 +0200 |
commit | 50fd745b4dec07e8e213cf2703b5cabcfa128225 (patch) | |
tree | c0341dcf5c4f3275cded07abeec6eefb3e427959 /nscd/netgroupcache.c | |
parent | 3ee7e9fe34a96cfbf2d39879c21eb36e70471ad1 (diff) | |
download | glibc-50fd745b4dec07e8e213cf2703b5cabcfa128225.tar.gz glibc-50fd745b4dec07e8e213cf2703b5cabcfa128225.tar.xz glibc-50fd745b4dec07e8e213cf2703b5cabcfa128225.zip |
Fix handling of netgroup cache in nscd
Diffstat (limited to 'nscd/netgroupcache.c')
-rw-r--r-- | nscd/netgroupcache.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c index 2d6c5aa459..dd06ce4fae 100644 --- a/nscd/netgroupcache.c +++ b/nscd/netgroupcache.c @@ -192,18 +192,26 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, const char *nuser = data.val.triple.user; const char *ndomain = data.val.triple.domain; - if (data.val.triple.host > data.val.triple.user - || data.val.triple.user > data.val.triple.domain) + if (nhost == NULL || nuser == NULL || ndomain == NULL + || nhost > nuser || nuser > ndomain) { - const char *last = MAX (nhost, - MAX (nuser, ndomain)); - size_t bufused = (last + strlen (last) + 1 - - buffer); + const char *last = nhost; + if (last == NULL + || (nuser != NULL && nuser > last)) + last = nuser; + if (last == NULL + || (ndomain != NULL && ndomain > last)) + last = ndomain; + + size_t bufused + = (last == NULL + ? buffilled + : last + strlen (last) + 1 - buffer); /* We have to make temporary copies. */ - size_t hostlen = strlen (nhost) + 1; - size_t userlen = strlen (nuser) + 1; - size_t domainlen = strlen (ndomain) + 1; + size_t hostlen = strlen (nhost ?: "") + 1; + size_t userlen = strlen (nuser ?: "") + 1; + size_t domainlen = strlen (ndomain ?: "") + 1; size_t needed = hostlen + userlen + domainlen; if (buflen - req->key_len - bufused < needed) @@ -226,11 +234,11 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req, } nhost = memcpy (buffer + bufused, - nhost, hostlen); + nhost ?: "", hostlen); nuser = memcpy ((char *) nhost + hostlen, - nuser, userlen); + nuser ?: "", userlen); ndomain = memcpy ((char *) nuser + userlen, - ndomain, domainlen); + ndomain ?: "", domainlen); } char *wp = buffer + buffilled; |