From 675b5fdc76ef63fd24fe95afc8a3c58ca5bb0247 Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 23 Jan 2008 09:46:13 +0000 Subject: [PATCH] Protect all vsb's (sbufs) with an assert that they did not overflow. I don't think it is likely that they would, but some users are running out of memory, so make it deterministic when it happens. Noticed by Coverity Scan (CID: 4-6) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2370 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_cli.c | 1 + varnish-cache/bin/varnishd/cache_synthetic.c | 1 + varnish-cache/bin/varnishd/cache_vary.c | 2 ++ varnish-cache/bin/varnishd/mgt_cli.c | 2 ++ varnish-cache/bin/varnishd/mgt_vcc.c | 4 ++++ varnish-cache/bin/varnishd/varnishd.c | 2 ++ 6 files changed, 12 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache_cli.c b/varnish-cache/bin/varnishd/cache_cli.c index aabe8d81..4936798d 100644 --- a/varnish-cache/bin/varnishd/cache_cli.c +++ b/varnish-cache/bin/varnishd/cache_cli.c @@ -125,6 +125,7 @@ CLI_Init(void) vsb_clear(cli->sb); cli_dispatch(cli, CLI_cmds, buf); vsb_finish(cli->sb); + AZ(vsb_overflowed(cli->sb)); i = cli_writeres(heritage.fds[1], cli); if (i) { VSL(SLT_Error, 0, "CLI write failed (errno=%d)", errno); diff --git a/varnish-cache/bin/varnishd/cache_synthetic.c b/varnish-cache/bin/varnishd/cache_synthetic.c index 2a8f01ae..fe7c3540 100644 --- a/varnish-cache/bin/varnishd/cache_synthetic.c +++ b/varnish-cache/bin/varnishd/cache_synthetic.c @@ -118,6 +118,7 @@ SYN_ErrorPage(struct sess *sp, int status, const char *reason) " \n" "\n"); vsb_finish(&vsb); + AZ(vsb_overflowed(&vsb)); w->acct.hdrbytes = WRK_Write(w, vsb_data(&vsb), vsb_len(&vsb)); (void)WRK_Flush(w); vsb_delete(&vsb); diff --git a/varnish-cache/bin/varnishd/cache_vary.c b/varnish-cache/bin/varnishd/cache_vary.c index 3db31a26..14eb6f0c 100644 --- a/varnish-cache/bin/varnishd/cache_vary.c +++ b/varnish-cache/bin/varnishd/cache_vary.c @@ -91,6 +91,7 @@ VRY_Create(const struct sess *sp) vsb_clear(sbh); vsb_printf(sbh, "%c%.*s:%c", 1 + (q - p), q - p, p, 0); vsb_finish(sbh); + AZ(vsb_overflowed(sbh)); /* Append to vary matching string */ vsb_bcat(sb, vsb_data(sbh), vsb_len(sbh)); @@ -122,6 +123,7 @@ VRY_Create(const struct sess *sp) vsb_printf(sb, "%c", 0); vsb_finish(sb); + AZ(vsb_overflowed(sb)); l = vsb_len(sb); sp->obj->vary = malloc(l); AN(sp->obj->vary); diff --git a/varnish-cache/bin/varnishd/mgt_cli.c b/varnish-cache/bin/varnishd/mgt_cli.c index 29e10e86..9453fcaa 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.c +++ b/varnish-cache/bin/varnishd/mgt_cli.c @@ -124,6 +124,7 @@ mcf_passthru(struct cli *cli, const char * const *av, void *priv) vsb_putc(sb, '\n'); xxxassert(!vsb_overflowed(sb)); vsb_finish(sb); + AZ(vsb_overflowed(sb)); i = write(cli_o, vsb_data(sb), vsb_len(sb)); xxxassert(i == vsb_len(sb)); vsb_delete(sb); @@ -325,6 +326,7 @@ mgt_cli_callback(const struct ev *e, int what) vsb_clear(cp->cli->sb); cli_dispatch(cp->cli, cli_proto, p); vsb_finish(cp->cli->sb); + AZ(vsb_overflowed(cp->cli->sb)); /* send the result back */ if (cli_writeres(cp->fdo, cp->cli)) diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index 6cbfcccd..b912ffdc 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -237,6 +237,7 @@ mgt_run_cc(const char *source, struct vsb *sb) vsb_new(&cmdsb, cmdline, sizeof cmdline, 0); mgt_make_cc_cmd(&cmdsb, sf, of); vsb_finish(&cmdsb); + AZ(vsb_overflowed(&cmdsb)); /* XXX check vsb state */ if (pipe(p) < 0) { @@ -430,6 +431,7 @@ mgt_vcc_default(const char *b_arg, const char *f_arg, int f_fd, int C_flag) vf = mgt_VccCompileFile(sb, f_arg, C_flag, f_fd); } vsb_finish(sb); + AZ(vsb_overflowed(sb)); if (vsb_len(sb) > 0) fprintf(stderr, "%s", vsb_data(sb)); vsb_delete(sb); @@ -511,6 +513,7 @@ mcf_config_inline(struct cli *cli, const char * const *av, void *priv) XXXAN(sb); vf = mgt_VccCompile(sb, av[3], NULL, 0); vsb_finish(sb); + AZ(vsb_overflowed(sb)); if (vsb_len(sb) > 0) cli_out(cli, "%s", vsb_data(sb)); vsb_delete(sb); @@ -544,6 +547,7 @@ mcf_config_load(struct cli *cli, const char * const *av, void *priv) XXXAN(sb); vf = mgt_VccCompileFile(sb, av[3], 0, -1); vsb_finish(sb); + AZ(vsb_overflowed(sb)); if (vsb_len(sb) > 0) cli_out(cli, "%s", vsb_data(sb)); vsb_delete(sb); diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index 56875c29..36e63c2d 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -342,6 +342,7 @@ cli_check(const struct cli *cli) return; } vsb_finish(cli->sb); + AZ(vsb_overflowed(cli->sb)); fprintf(stderr, "Error:\n%s\n", vsb_data(cli->sb)); exit (2); } @@ -477,6 +478,7 @@ main(int argc, char *argv[]) if (cli[0].result != CLIS_OK) { fprintf(stderr, "Parameter errors:\n"); vsb_finish(cli[0].sb); + AZ(vsb_overflowed(cli[0].sb)); fprintf(stderr, "%s\n", vsb_data(cli[0].sb)); exit(1); } -- 2.39.5