aboutsummaryrefslogtreecommitdiff
path: root/nscd/initgrcache.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2014-04-30 11:57:09 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2014-04-30 11:57:09 +0530
commit1cdeb2372ddecac0dfe0c132a033e9590ffa07d2 (patch)
treee0265a463391655f3b8fa068b1578ec5e2d11ad0 /nscd/initgrcache.c
parent16b293a7a6f65d8ff348a603d19e8fd4372fa3a9 (diff)
downloadglibc-1cdeb2372ddecac0dfe0c132a033e9590ffa07d2.tar
glibc-1cdeb2372ddecac0dfe0c132a033e9590ffa07d2.tar.gz
glibc-1cdeb2372ddecac0dfe0c132a033e9590ffa07d2.tar.bz2
glibc-1cdeb2372ddecac0dfe0c132a033e9590ffa07d2.zip
Consolidate code to initialize nscd dataset header
This patch consolidates the code to initialize the header of a dataset into a single set of functions (one for positive and another for negative datasets) primarily to reduce repetition of code. The secondary reason is to simplify Patch 2/2 which fixes the problem of an uninitialized byte in the header by initializing an unused field in the structure and hence preventing a possible data leak into the cache file.
Diffstat (limited to 'nscd/initgrcache.c')
-rw-r--r--nscd/initgrcache.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index 1bf9f0d7f4..361319fa7e 100644
--- a/nscd/initgrcache.c
+++ b/nscd/initgrcache.c
@@ -213,14 +213,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
+ req->key_len), 1)) != NULL)
{
- dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
- dataset->head.recsize = total;
- dataset->head.notfound = true;
- dataset->head.nreloads = 0;
- dataset->head.usable = true;
-
- /* Compute the timeout time. */
- timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
+ timeout = datahead_init_neg (&dataset->head,
+ (sizeof (struct dataset)
+ + req->key_len), total,
+ db->negtimeout);
/* This is the reply. */
memcpy (&dataset->resp, &notfound, total);
@@ -276,14 +272,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
alloca_used = true;
}
- dataset->head.allocsize = total + req->key_len;
- dataset->head.recsize = total - offsetof (struct dataset, resp);
- dataset->head.notfound = false;
- dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
- dataset->head.usable = true;
-
- /* Compute the timeout time. */
- timeout = dataset->head.timeout = time (NULL) + db->postimeout;
+ timeout = datahead_init_pos (&dataset->head, total + req->key_len,
+ total - offsetof (struct dataset, resp),
+ he == NULL ? 0 : dh->nreloads + 1,
+ db->postimeout);
dataset->resp.version = NSCD_VERSION;
dataset->resp.found = 1;