From 7e71e55f16e037042671cf70f8f130f26e494b74 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 11 May 2008 03:03:14 +0000 Subject: [PATCH] * nscd/cache.c (cache_add): Before returning with failure and this is the first use of the record, mark it as unusable. * nscd/aicache.c: Don't touch the dataset after cache_add returns reporting a failure. * nscd/grpcache.c: Likewise * nscd/hstcache.c: Likewise. * nscd/initgrcache.c: Likewise. * nscd/pwdcache.c: Likewise. * nscd/servicecache.c: Likewise. --- ChangeLog | 12 ++++++++++++ nscd/aicache.c | 6 ++---- nscd/grpcache.c | 26 +++++--------------------- nscd/hstcache.c | 13 ++++--------- nscd/initgrcache.c | 13 ++++--------- nscd/pwdcache.c | 27 +++++---------------------- nscd/servicescache.c | 13 ++++--------- 7 files changed, 36 insertions(+), 74 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2385b10..fe91d7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-05-10 Ulrich Drepper + + * nscd/cache.c (cache_add): Before returning with failure and this + is the first use of the record, mark it as unusable. + * nscd/aicache.c: Don't touch the dataset after cache_add returns + reporting a failure. + * nscd/grpcache.c: Likewise + * nscd/hstcache.c: Likewise. + * nscd/initgrcache.c: Likewise. + * nscd/pwdcache.c: Likewise. + * nscd/servicecache.c: Likewise. + 2008-05-10 Roland McGrath [BZ #6505] diff --git a/nscd/aicache.c b/nscd/aicache.c index 4db3e65..918efc9 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -556,10 +556,8 @@ next_nip: /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, key_copy, req->key_len, &dataset->head, true, - db, uid) < 0) - /* Ensure the data can be recovered. */ - dataset->head.usable = false; + (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, + true, db, uid); pthread_rwlock_unlock (&db->lock); diff --git a/nscd/grpcache.c b/nscd/grpcache.c index dbc406f..9921ae3 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -146,10 +146,8 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, &dataset->strdata, req->key_len, - &dataset->head, true, db, owner) < 0) - /* Ensure the data can be recovered. */ - dataset->head.usable = false; + (void) cache_add (req->type, &dataset->strdata, req->key_len, + &dataset->head, true, db, owner); pthread_rwlock_unlock (&db->lock); @@ -356,12 +354,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, { if (cache_add (GETGRBYGID, cp, key_offset, &dataset->head, true, db, owner) < 0) - { - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; - goto out; - } + goto out; first = false; } @@ -370,12 +363,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, { if (cache_add (GETGRBYNAME, key_copy, key_len + 1, &dataset->head, true, db, owner) < 0) - { - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; - goto out; - } + goto out; first = false; } @@ -389,12 +377,8 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, { if (req->type == GETGRBYNAME && db->propagate) (void) cache_add (GETGRBYGID, cp, key_offset, &dataset->head, - req->type != GETGRBYNAME, db, owner); + false, db, owner); } - else if (first) - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; out: pthread_rwlock_unlock (&db->lock); diff --git a/nscd/hstcache.c b/nscd/hstcache.c index b93d418..3ceb671 100644 --- a/nscd/hstcache.c +++ b/nscd/hstcache.c @@ -155,10 +155,8 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, &dataset->strdata, req->key_len, - &dataset->head, true, db, owner) < 0) - /* Ensure the data can be recovered. */ - dataset->head.usable = false; + (void) cache_add (req->type, &dataset->strdata, req->key_len, + &dataset->head, true, db, owner); pthread_rwlock_unlock (&db->lock); @@ -409,11 +407,8 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, || req->type == GETHOSTBYADDR || req->type == GETHOSTBYADDRv6); - if (cache_add (req->type, key_copy, req->key_len, - &dataset->head, true, db, owner) < 0) - /* Could not allocate memory. Make sure the - data gets discarded. */ - dataset->head.usable = false; + (void) cache_add (req->type, key_copy, req->key_len, + &dataset->head, true, db, owner); pthread_rwlock_unlock (&db->lock); } diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index 4d6513b..94e909d 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -230,10 +230,8 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, key_copy, req->key_len, - &dataset->head, true, db, uid) < 0) - /* Ensure the data can be recovered. */ - dataset->head.usable = false; + (void) cache_add (req->type, key_copy, req->key_len, + &dataset->head, true, db, uid); pthread_rwlock_unlock (&db->lock); @@ -399,11 +397,8 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true, - db, uid) < 0) - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; + (void) cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true, + db, uid); pthread_rwlock_unlock (&db->lock); } diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index e1bf6e9..2d0a265 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -153,11 +153,8 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, key_copy, req->key_len, - &dataset->head, true, db, owner) < 0) - /* Ensure the data can be recovered. */ - dataset->head.usable = false; - + (void) cache_add (req->type, key_copy, req->key_len, + &dataset->head, true, db, owner); pthread_rwlock_unlock (&db->lock); @@ -352,12 +349,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, { if (cache_add (GETPWBYUID, cp, key_offset, &dataset->head, true, db, owner) < 0) - { - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; - goto out; - } + goto out; first = false; } @@ -366,12 +358,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, { if (cache_add (GETPWBYNAME, key_copy, key_len + 1, &dataset->head, true, db, owner) < 0) - { - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; - goto out; - } + goto out; first = false; } @@ -384,12 +371,8 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, { if (req->type == GETPWBYNAME && db->propagate) (void) cache_add (GETPWBYUID, cp, key_offset, &dataset->head, - req->type != GETPWBYNAME, db, owner); + false, db, owner); } - else if (first) - /* Could not allocate memory. Make sure the data gets - discarded. */ - dataset->head.usable = false; out: pthread_rwlock_unlock (&db->lock); diff --git a/nscd/servicescache.c b/nscd/servicescache.c index 164b6e2..c6f0b47 100644 --- a/nscd/servicescache.c +++ b/nscd/servicescache.c @@ -136,10 +136,8 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, &dataset->strdata, req->key_len, - &dataset->head, true, db, owner) < 0) - /* Ensure the data can be recovered. */ - dataset->head.usable = false; + (void) cache_add (req->type, &dataset->strdata, req->key_len, + &dataset->head, true, db, owner); pthread_rwlock_unlock (&db->lock); @@ -332,11 +330,8 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, /* Now get the lock to safely insert the records. */ pthread_rwlock_rdlock (&db->lock); - if (cache_add (req->type, key_copy, req->key_len, - &dataset->head, true, db, owner) < 0) - /* Could not allocate memory. Make sure the - data gets discarded. */ - dataset->head.usable = false; + (void) cache_add (req->type, key_copy, req->key_len, + &dataset->head, true, db, owner); pthread_rwlock_unlock (&db->lock); } -- 2.7.4