Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit cd2cfbd

Browse files
committed
Make incomplete commands in -I cli_file a fatal error.
Fixes: 3995
1 parent 3110d6f commit cd2cfbd

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

bin/varnishd/mgt/mgt_cli.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ mgt_cli_cb_after(const struct cli *cli)
341341

342342
MGT_Complain(C_CLI, "CLI %s Wr %03u %s",
343343
cli->ident, cli->result, VSB_data(cli->sb));
344-
if (cli->priv == stderr &&
345-
cli->result != CLIS_OK && *VSB_data(cli->cmd) != '-') {
344+
if (cli->priv != stderr)
345+
return;
346+
if (cli->result == CLIS_TRUNCATED)
347+
ARGV_ERR("-I file had incomplete CLI command at the end\n");
348+
if (cli->result != CLIS_OK && *VSB_data(cli->cmd) != '-') {
346349
ARGV_ERR("-I file CLI command failed (%d)\n%s\n",
347350
cli->result, VSB_data(cli->sb));
348351
}

bin/varnishtest/tests/u00000.vtc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,23 @@ shell -err -expect {Cannot read -f file} {
169169
}
170170

171171
# varnishd -spersistent is tested in p00000.vtc
172+
173+
# Test that incomplete CLI commands in -I causes failure
174+
175+
process p1 {
176+
echo -n foobar > ${tmpdir}/_foobar
177+
exec varnishd -n ${tmpdir}/v0 -d -a :0 -I ${tmpdir}/_foobar 2>&1
178+
} -expect-exit 2 -start
179+
180+
process p1 -expect-text 0 0 "-I file had incomplete CLI command at the end"
181+
process p1 -screen-dump
182+
process p1 -wait
183+
184+
process p1 {
185+
echo 'foobar << blabla > ${tmpdir}/_foobar
186+
exec varnishd -n ${tmpdir}/v0 -d -a :0 -I ${tmpdir}/_foobar 2>&1
187+
} -expect-exit 2 -start
188+
189+
process p1 -expect-text 0 0 "-I file had incomplete CLI command at the end"
190+
process p1 -screen-dump
191+
process p1 -wait

lib/libvarnish/vcli_serve.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,13 @@ cls_close_fd(struct VCLS *cs, struct VCLS_fd *cfd)
522522
CHECK_OBJ_NOTNULL(cfd, VCLS_FD_MAGIC);
523523

524524
VTAILQ_REMOVE(&cs->fds, cfd, list);
525+
if (cfd->cli->cmd != NULL) {
526+
(void)VSB_finish(cfd->cli->cmd);
527+
cfd->cli->result = CLIS_TRUNCATED;
528+
if (cs->after != NULL)
529+
cs->after(cfd->cli);
530+
VSB_destroy(&cfd->cli->cmd);
531+
}
525532
cs->nfd--;
526533
VSB_destroy(&cfd->cli->sb);
527534
if (cfd->closefunc != NULL)

0 commit comments

Comments
 (0)