[master] 00c7e7b Protect against use-after-free/unitialized

Guillaume Quintard guillaume at varnish-software.com
Wed Aug 31 13:52:14 CEST 2016


commit 00c7e7b24201f2a5a7cb5c2ae9c31173dd6da6ef
Author: Guillaume Quintard <guillaume at varnish-software.com>
Date:   Tue Aug 30 11:11:35 2016 +0200

    Protect against use-after-free/unitialized

diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 6f58bf1..47b7709 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -136,7 +136,7 @@ varnish_ask_cli(const struct varnish *v, const char *cmd, char **repl)
 static void
 wait_stopped(const struct varnish *v)
 {
-	char *r;
+	char *r = NULL;
 	enum VCLI_status_e st;
 
 	while (1) {
@@ -150,6 +150,7 @@ wait_stopped(const struct varnish *v)
 			break;
 		}
 		free(r);
+		r = NULL;
 		(void)usleep(200000);
 	}
 }
@@ -160,7 +161,7 @@ wait_stopped(const struct varnish *v)
 static void
 wait_running(const struct varnish *v)
 {
-	char *r;
+	char *r = NULL;
 	enum VCLI_status_e st;
 
 	while (1) {
@@ -180,6 +181,7 @@ wait_running(const struct varnish *v)
 			break;
 		}
 		free(r);
+		r = NULL;
 		(void)usleep(200000);
 	}
 }
@@ -392,7 +394,7 @@ varnish_launch(struct varnish *v)
 	struct pollfd fd[2];
 	enum VCLI_status_e u;
 	const char *err;
-	char *r;
+	char *r = NULL;
 
 	v->vd = VSM_New();
 
@@ -521,6 +523,7 @@ varnish_launch(struct varnish *v)
 	VCLI_AuthResponse(nfd, r, abuf + 5);
 	AZ(close(nfd));
 	free(r);
+	r = NULL;
 	strcat(abuf, "\n");
 
 	u = varnish_ask_cli(v, abuf, &r);
@@ -542,7 +545,7 @@ static void
 varnish_start(struct varnish *v)
 {
 	enum VCLI_status_e u;
-	char *resp, *h, *p;
+	char *resp = NULL, *h, *p;
 
 	if (v->cli_fd < 0)
 		varnish_launch(v);
@@ -556,6 +559,7 @@ varnish_start(struct varnish *v)
 		vtc_log(v->vl, 0, "CLI start command failed: %u %s", u, resp);
 	wait_running(v);
 	free(resp);
+	resp = NULL;
 	u = varnish_ask_cli(v, "debug.xid 999", &resp);
 	if (vtc_error)
 		return;
@@ -563,6 +567,7 @@ varnish_start(struct varnish *v)
 		vtc_log(v->vl, 0, "CLI debug.xid command failed: %u %s",
 		    u, resp);
 	free(resp);
+	resp = NULL;
 	u = varnish_ask_cli(v, "debug.listen_address", &resp);
 	if (vtc_error)
 		return;



More information about the varnish-commit mailing list