[sheepdog] [PATCH 1/3] sheep: fill zero to avoid reading uninitialized data

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Sep 7 09:45:26 CEST 2012


This might be unnecessary, but It is a bit weird to calculate sha1
hashes based on uninitialized data.  This also silences valgrind
errors.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/farm/snap.c  |    2 +-
 sheep/farm/trunk.c |    4 ++--
 sheep/ops.c        |    1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sheep/farm/snap.c b/sheep/farm/snap.c
index 072843f..73f9758 100644
--- a/sheep/farm/snap.c
+++ b/sheep/farm/snap.c
@@ -130,7 +130,7 @@ int snap_file_write(uint32_t epoch, struct sd_node *nodes, int nr_nodes,
 {
 	int ret = 0;
 	struct strbuf buf = STRBUF_INIT;
-	struct sha1_file_hdr hdr;
+	struct sha1_file_hdr hdr = {};
 
 	memcpy(hdr.tag, TAG_SNAP, TAG_LEN);
 	hdr.size = nr_nodes * sizeof(*nodes) + SHA1_LEN;
diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index 4d955a3..ca7631b 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -78,8 +78,8 @@ static int inc_object_nr(uint64_t oid, void *arg)
 int trunk_file_write(unsigned char *outsha1)
 {
 	struct strbuf buf;
-	struct sha1_file_hdr hdr;
-	struct trunk_entry entry;
+	struct sha1_file_hdr hdr = {};
+	struct trunk_entry entry = {};
 	struct dirent *d;
 	DIR *dir;
 	uint64_t data_size, oid, object_nr = 0;
diff --git a/sheep/ops.c b/sheep/ops.c
index c06ce81..6aff0d5 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -452,6 +452,7 @@ static int local_stat_cluster(struct request *req)
 			break;
 
 		log = (struct epoch_log *)req->data + i;
+		memset(log, 0, sizeof(*log));
 		log->epoch = epoch;
 		log->ctime = get_cluster_ctime();
 		log->nr_nodes = epoch_log_read(epoch, log->nodes,
-- 
1.7.2.5




More information about the sheepdog mailing list