From: phk Date: Sat, 5 Aug 2006 12:22:46 +0000 (+0000) Subject: Make sure we don't overflow the line buffer X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f92fcf16958020c8450d9423cfa35f6ed2489979;p=varnish Make sure we don't overflow the line buffer Remove unused #include git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@662 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_cli.c b/varnish-cache/bin/varnishd/cache_cli.c index 9a5c7a29..5498b5e0 100644 --- a/varnish-cache/bin/varnishd/cache_cli.c +++ b/varnish-cache/bin/varnishd/cache_cli.c @@ -9,7 +9,6 @@ #include #include -#include "libvarnish.h" #include "shmlog.h" #include "cli.h" #include "cli_priv.h" @@ -72,7 +71,7 @@ CLI_Init(void) i = poll(pfd, 1, 5000); if (i == 0) continue; - if (nbuf == lbuf) { + if ((nbuf + 2) >= lbuf) { lbuf += lbuf; buf = realloc(buf, lbuf); assert(buf != NULL); @@ -80,6 +79,7 @@ CLI_Init(void) i = read(heritage.fds[2], buf + nbuf, lbuf - nbuf); if (i <= 0) { VSL(SLT_Error, 0, "CLI read %d (errno=%d)", i, errno); + free(buf); return; } nbuf += i; @@ -94,6 +94,7 @@ CLI_Init(void) i = cli_writeres(heritage.fds[1], cli); if (i) { VSL(SLT_Error, 0, "CLI write failed (errno=%d)", errno); + free(buf); return; } VSL(SLT_CLI, 0, "Wr %d %d %s",