Blame SOURCES/unbound-1.4.20-coverity_scan.patch

4fd01f
From de7c59d25d9fd2464543d649951b2ae47c2a839b Mon Sep 17 00:00:00 2001
4fd01f
From: wouter <wouter@be551aaa-1e26-0410-a405-d3ace91eadb9>
4fd01f
Date: Wed, 21 Aug 2013 13:31:09 +0000
4fd01f
Subject: [PATCH] - Fix#520: Errors found by static analysis from Tomas
4fd01f
 Hozza(redhat).
4fd01f
4fd01f
git-svn-id: http://unbound.nlnetlabs.nl/svn/trunk@2942 be551aaa-1e26-0410-a405-d3ace91eadb9
4fd01f
Signed-off-by: Tomas Hozza <thozza@redhat.com>
4fd01f
---
4fd01f
 libunbound/libworker.c | 3 +++
4fd01f
 testcode/streamtcp.c   | 2 +-
4fd01f
 util/tube.c            | 2 +-
4fd01f
 validator/autotrust.c  | 6 +++++-
4fd01f
 4 files changed, 10 insertions(+), 3 deletions(-)
4fd01f
4fd01f
diff --git a/libunbound/libworker.c b/libunbound/libworker.c
4fd01f
index dd3316d..8f2aa48 100644
4fd01f
--- a/libunbound/libworker.c
4fd01f
+++ b/libunbound/libworker.c
4fd01f
@@ -198,7 +198,10 @@ libworker_setup(struct ub_ctx* ctx, int is_bg)
4fd01f
 	}
4fd01f
 	numports = cfg_condense_ports(cfg, &ports);
4fd01f
 	if(numports == 0) {
4fd01f
+		int locked = !w->is_bg || w->is_bg_thread;
4fd01f
 		libworker_delete(w);
4fd01f
+		if(locked)
4fd01f
+			lock_basic_unlock(&ctx->cfglock);
4fd01f
 		return NULL;
4fd01f
 	}
4fd01f
 	w->back = outside_network_create(w->base, cfg->msg_buffer_size,
4fd01f
diff --git a/testcode/streamtcp.c b/testcode/streamtcp.c
4fd01f
index dbdf140..06a18e4 100644
4fd01f
--- a/testcode/streamtcp.c
4fd01f
+++ b/testcode/streamtcp.c
4fd01f
@@ -121,9 +121,9 @@ write_q(int fd, int udp, SSL* ssl, ldns_buffer* buf, uint16_t id,
4fd01f
 		exit(1);
4fd01f
 	}
4fd01f
 	qinfo.qname = memdup(ldns_rdf_data(rdf), ldns_rdf_size(rdf));
4fd01f
+	if(!qinfo.qname) fatal_exit("out of memory");
4fd01f
 	(void)dname_count_size_labels(qinfo.qname, &qinfo.qname_len);
4fd01f
 	ldns_rdf_deep_free(rdf);
4fd01f
-	if(!qinfo.qname) fatal_exit("out of memory");
4fd01f
 
4fd01f
 	/* qtype and qclass */
4fd01f
 	qinfo.qtype = ldns_get_rr_type_by_name(strtype);
4fd01f
diff --git a/util/tube.c b/util/tube.c
4fd01f
index 28c51d7..fde8496 100644
4fd01f
--- a/util/tube.c
4fd01f
+++ b/util/tube.c
4fd01f
@@ -368,7 +368,7 @@ int tube_read_msg(struct tube* tube, uint8_t** buf, uint32_t* len,
4fd01f
 		return 0;
4fd01f
 	}
4fd01f
 	d = 0;
4fd01f
-	while(d != (ssize_t)*len) {
4fd01f
+	while(d < (ssize_t)*len) {
4fd01f
 		if((r=read(fd, (*buf)+d, (size_t)((ssize_t)*len)-d)) == -1) {
4fd01f
 			log_err("tube msg read failed: %s", strerror(errno));
4fd01f
 			(void)fd_set_nonblock(fd);
4fd01f
diff --git a/validator/autotrust.c b/validator/autotrust.c
4fd01f
index 1e24b4c..dc7cbf6 100644
4fd01f
--- a/validator/autotrust.c
4fd01f
+++ b/validator/autotrust.c
4fd01f
@@ -976,9 +976,13 @@ void autr_write_file(struct module_env* env, struct trust_anchor* tp)
4fd01f
 	char* fname = tp->autr->file;
4fd01f
 	char tempf[2048];
4fd01f
 	log_assert(tp->autr);
4fd01f
+	if(!env) {
4fd01f
+		log_err("autr_write_file: Module environment is NULL.");
4fd01f
+		return;
4fd01f
+	}
4fd01f
 	/* unique name with pid number and thread number */
4fd01f
 	snprintf(tempf, sizeof(tempf), "%s.%d-%d", fname, (int)getpid(),
4fd01f
-		env&&env->worker?*(int*)env->worker:0);
4fd01f
+		env->worker?*(int*)env->worker:0);
4fd01f
 	verbose(VERB_ALGO, "autotrust: write to disk: %s", tempf);
4fd01f
 	out = fopen(tempf, "w");
4fd01f
 	if(!out) {
4fd01f
-- 
4fd01f
1.8.3.1
4fd01f