Skip to content

Commit

Permalink
Make incomplete commands in -I cli_file a fatal error.
Browse files Browse the repository at this point in the history
Fixes: 3995
  • Loading branch information
bsdphk committed Oct 11, 2023
1 parent 3110d6f commit cd2cfbd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/varnishd/mgt/mgt_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,11 @@ mgt_cli_cb_after(const struct cli *cli)

MGT_Complain(C_CLI, "CLI %s Wr %03u %s",
cli->ident, cli->result, VSB_data(cli->sb));
if (cli->priv == stderr &&
cli->result != CLIS_OK && *VSB_data(cli->cmd) != '-') {
if (cli->priv != stderr)
return;
if (cli->result == CLIS_TRUNCATED)
ARGV_ERR("-I file had incomplete CLI command at the end\n");
if (cli->result != CLIS_OK && *VSB_data(cli->cmd) != '-') {
ARGV_ERR("-I file CLI command failed (%d)\n%s\n",
cli->result, VSB_data(cli->sb));
}
Expand Down
20 changes: 20 additions & 0 deletions bin/varnishtest/tests/u00000.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,23 @@ shell -err -expect {Cannot read -f file} {
}

# varnishd -spersistent is tested in p00000.vtc

# Test that incomplete CLI commands in -I causes failure

process p1 {
echo -n foobar > ${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 p1 {
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
7 changes: 7 additions & 0 deletions lib/libvarnish/vcli_serve.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ 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) {
(void)VSB_finish(cfd->cli->cmd);
cfd->cli->result = CLIS_TRUNCATED;
if (cs->after != NULL)
cs->after(cfd->cli);
VSB_destroy(&cfd->cli->cmd);
}
cs->nfd--;
VSB_destroy(&cfd->cli->sb);
if (cfd->closefunc != NULL)
Expand Down

0 comments on commit cd2cfbd

Please sign in to comment.