[6.0] c58af7edf Dup(2) stderr before calling VCLS on -I argument.

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Oct 31 13:08:24 UTC 2018


commit c58af7edf19f05556415dbe3f849ee0e74684c0b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Sep 26 19:40:05 2018 +0000

    Dup(2) stderr before calling VCLS on -I argument.
    
    Fixes: #2782

diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 7a427d5bf..d03ff2106 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -278,6 +278,8 @@ mgt_launch_child(struct cli *cli)
 	/* Open pipe for mgt->child CLI */
 	AZ(pipe(cp));
 	heritage.cli_in = cp[0];
+	assert(cp[0] > STDERR_FILENO);	// See #2782
+	assert(cp[1] > STDERR_FILENO);
 	MCH_Fd_Inherit(heritage.cli_in, "cli_in");
 	child_cli_out = cp[1];
 
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index aada3ce2c..237fb0f7f 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -861,7 +861,8 @@ main(int argc, char * const *argv)
 
 	if (I_fd >= 0) {
 		fprintf(stderr, "BEGIN of -I file processing\n");
-		mgt_cli_setup(I_fd, 2, 1, "-I file", mgt_I_close, stderr);
+		/* We must dup stderr, because VCLS closes the output fd */
+		mgt_cli_setup(I_fd, dup(2), 1, "-I file", mgt_I_close, stderr);
 		while (I_fd >= 0) {
 			o = VEV_Once(mgt_evb);
 			if (o != 1)


More information about the varnish-commit mailing list