[master] 101ffbb46 Better fix & test for incomplete << nonce cli commands.

Poul-Henning Kamp phk at FreeBSD.org
Wed Oct 11 12:23:05 UTC 2023


commit 101ffbb46a3be84d7c5a6dd221e3e0949d08fd6e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 11 12:22:01 2023 +0000

    Better fix & test for incomplete << nonce cli commands.
    
    Fixes #3995

diff --git a/bin/varnishtest/tests/u00000.vtc b/bin/varnishtest/tests/u00000.vtc
index 8efeb3bc0..831dd9eac 100644
--- a/bin/varnishtest/tests/u00000.vtc
+++ b/bin/varnishtest/tests/u00000.vtc
@@ -181,11 +181,11 @@ process p1 -expect-text 0 0 "-I file had incomplete CLI command at the end"
 process p1 -screen-dump
 process p1 -wait
 
-process p1 {
-	echo 'foobar << blabla > ${tmpdir}/_foobar
+process p2 {
+	echo 'foobar << blabla' > ${tmpdir}/_foobar
 	exec varnishd -n ${tmpdir}/v0 -d -a :0 -I ${tmpdir}/_foobar 2>&1
 } -expect-exit 2 -start
 
-process p1 -expect-text 0 0 "-I file had incomplete CLI command at the end"
-process p1 -screen-dump
-process p1 -wait
+process p2 -expect-text 0 0 "-I file had incomplete CLI command at the end"
+process p2 -screen-dump
+process p2 -wait
diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c
index 9dee27e36..dbb384a0f 100644
--- a/lib/libvarnish/vcli_serve.c
+++ b/lib/libvarnish/vcli_serve.c
@@ -428,6 +428,7 @@ cls_feed(struct VCLS_fd *cfd, const char *p, const char *e)
 			if (*cfd->match == '\0' && (*p == '\r' || *p == '\n')) {
 				AZ(VSB_finish(cfd->last_arg));
 				// NB: VAV lib internals trusted
+				cfd->match = NULL;
 				REPLACE(cfd->argv[cfd->argc - 1], NULL);
 				REPLACE(cfd->argv[cfd->argc - 2], NULL);
 				cfd->argv[cfd->argc - 2] =
@@ -522,7 +523,12 @@ cls_close_fd(struct VCLS *cs, struct VCLS_fd *cfd)
 	CHECK_OBJ_NOTNULL(cfd, VCLS_FD_MAGIC);
 
 	VTAILQ_REMOVE(&cs->fds, cfd, list);
-	if (cfd->cli->cmd != NULL) {
+	if (cfd->match != NULL) {
+		cfd->cli->result = CLIS_TRUNCATED;
+		if (cs->after != NULL)
+			cs->after(cfd->cli);
+		VSB_destroy(&cfd->last_arg);
+	} else if (cfd->cli->cmd != NULL) {
 		(void)VSB_finish(cfd->cli->cmd);
 		cfd->cli->result = CLIS_TRUNCATED;
 		if (cs->after != NULL)


More information about the varnish-commit mailing list