[master] e1c4d9a Undefined behaviour is undefined

Federico G. Schwindt fgsch at lodoss.net
Tue May 30 23:00:07 CEST 2017


commit e1c4d9a6db62560360cc0c509f3244e43ca0047f
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Tue May 30 21:46:14 2017 +0100

    Undefined behaviour is undefined
    
    Spotted by ubsan.

diff --git a/bin/varnishd/hpack/vhp_table.c b/bin/varnishd/hpack/vhp_table.c
index 3357844..3ac2996 100644
--- a/bin/varnishd/hpack/vhp_table.c
+++ b/bin/varnishd/hpack/vhp_table.c
@@ -373,10 +373,12 @@ VHT_SetProtoMax(struct vht_table *tbl, size_t protomax)
 	if (buf == NULL)
 		return (-1);
 
-	memcpy(buf, tbl->buf, tbl->size);
-	memcpy(ENTRIES(buf, bufsize, tbl->n), TBLENTRIES(tbl),
-	    sizeof (struct vht_entry) * tbl->n);
-	free(tbl->buf);
+	if (tbl->buf != NULL) {
+		memcpy(buf, tbl->buf, tbl->size);
+		memcpy(ENTRIES(buf, bufsize, tbl->n), TBLENTRIES(tbl),
+		    sizeof (struct vht_entry) * tbl->n);
+		free(tbl->buf);
+	}
 	tbl->buf = buf;
 	tbl->bufsize = bufsize;
 	tbl->protomax = protomax;
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index c79d886..7b5f3e2 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -400,13 +400,17 @@ parse_data(struct stream *s, struct frame *f)
 		vtc_log(hp->vl, 4, "padding: %3d", f->md.padded);
 	}
 
-	if (!size)
-		vtc_log(hp->vl, 4, "s%u - no data", s->id);
-
 	if (s->id)
 		s->ws -= size;
+
 	s->hp->ws -= size;
 
+	if (!size) {
+		AZ(data);
+		vtc_log(hp->vl, 4, "s%u - no data", s->id);
+		return;
+	}
+
 	if (s->body) {
 		s->body = realloc(s->body, s->bodylen + size + 1L);
 	} else {
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index e4ad629..7c8011f 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -160,9 +160,10 @@ vev_get_sig(int sig)
 	if (os == NULL)
 		return (ENOMEM);
 
-	memcpy(os, vev_sigs, vev_nsig * sizeof *os);
-
-	free(vev_sigs);
+	if (vev_sigs != NULL) {
+		memcpy(os, vev_sigs, vev_nsig * sizeof *os);
+		free(vev_sigs);
+	}
 	vev_sigs = os;
 	vev_nsig = sig + 1;
 



More information about the varnish-commit mailing list