From 1cdeb2372ddecac0dfe0c132a033e9590ffa07d2 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Wed, 30 Apr 2014 11:57:09 +0530 Subject: 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. --- nscd/grpcache.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'nscd/grpcache.c') diff --git a/nscd/grpcache.c b/nscd/grpcache.c index b5a33eb347..df59fa79a1 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -128,14 +128,10 @@ cache_addgr (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 = t + db->negtimeout; + timeout = datahead_init_neg (&dataset->head, + (sizeof (struct dataset) + + req->key_len), total, + db->negtimeout); /* This is the reply. */ memcpy (&dataset->resp, ¬found, total); @@ -232,14 +228,10 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, dataset_temporary = true; } - dataset->head.allocsize = total + n; - 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 = t + db->postimeout; + timeout = datahead_init_pos (&dataset->head, total + n, + total - offsetof (struct dataset, resp), + he == NULL ? 0 : dh->nreloads + 1, + db->postimeout); dataset->resp.version = NSCD_VERSION; dataset->resp.found = 1; -- cgit 1.4.1