Commit c3da8ae5 authored by Tollef Fog Heen's avatar Tollef Fog Heen

asprintf cleanup

glibc and FreeBSD libc differ in how they handle asprintf allocation
failures.  Make sure we handle both cases properly and clean up the
includes a bit.

Fixes #334

git-svn-id: http://www.varnish-cache.org/svn/trunk@4436 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent d83b64f5
......@@ -46,9 +46,7 @@ SVNID("$Id$")
#include <unistd.h>
#include <sys/socket.h>
#ifndef HAVE_VASPRINTF
#include "compat/vasprintf.h"
#endif
#ifndef HAVE_SRANDOMDEV
#include "compat/srandomdev.h"
......@@ -593,7 +591,7 @@ telnet_accept(const struct vev *ev, int what)
TCP_myname(ev->fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
TCP_name((void*)&addr, addrlen, abuf2, sizeof abuf2,
pbuf2, sizeof pbuf2);
asprintf(&p, "telnet %s:%s %s:%s", abuf2, pbuf2, abuf1, pbuf1);
assert(asprintf(&p, "telnet %s:%s %s:%s", abuf2, pbuf2, abuf1, pbuf1) > 0);
XXXAN(p);
(void)telnet_new(i);
......
......@@ -44,9 +44,7 @@ SVNID("$Id$")
#include <string.h>
#include <unistd.h>
#ifndef HAVE_ASPRINTF
#include "compat/asprintf.h"
#endif
#include "vsb.h"
#include "libvcl.h"
......
......@@ -55,6 +55,7 @@ SVNID("$Id$")
#include <sys/vfs.h>
#endif
#include "compat/asprintf.h"
#include "mgt.h"
#include "stevedore.h"
......@@ -106,7 +107,7 @@ STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx)
ctx, fn);
if (S_ISDIR(st.st_mode)) {
asprintf(&q, "%s/varnish.XXXXXX", fn);
xxxassert(asprintf(&q, "%s/varnish.XXXXXX", fn) > 0);
XXXAN(q);
fd = mkstemp(q);
if (fd < 0)
......
......@@ -46,10 +46,6 @@ SVNID("$Id$")
#include <string.h>
#include <unistd.h>
#ifndef HAVE_ASPRINTF
#include "compat/asprintf.h"
#endif
#include "shmlog.h"
#include "cache.h"
#include "stevedore.h"
......
......@@ -48,6 +48,7 @@ SVNID("$Id$")
#include <time.h>
#include <unistd.h>
#include "compat/asprintf.h"
#include "compat/daemon.h"
#ifndef HAVE_STRLCPY
......@@ -435,10 +436,11 @@ Symbol_hack(const char *a0)
FILE *fi;
uintptr_t a;
struct symbols *s;
int i;
p = NULL;
asprintf(&p, "nm -an %s 2>/dev/null", a0);
if (p == NULL)
i = asprintf(&p, "nm -an %s 2>/dev/null", a0);
if (i < 0 || p == NULL)
return;
fi = popen(p, "r");
free(p);
......
......@@ -40,6 +40,7 @@ SVNID("$Id$")
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include "compat/asprintf.h"
#include "libvarnish.h"
#include "vsb.h"
......@@ -106,7 +107,7 @@ macro_def(struct vtclog *vl, const char *instance, const char *name,
va_start(ap, fmt);
free(m->val);
m->val = NULL;
(void)vasprintf(&m->val, fmt, ap);
assert(vasprintf(&m->val, fmt, ap) >= 0);
va_end(ap);
AN(m->val);
vtc_log(vl, 4, "macro def %s=%s", name, m->val);
......
......@@ -46,6 +46,7 @@ SVNID("$Id$")
#include <sys/wait.h>
#include <sys/socket.h>
#include "compat/asprintf.h"
#include "vqueue.h"
#include "miniobj.h"
#include "libvarnish.h"
......@@ -153,12 +154,13 @@ varnish_new(const char *name)
REPLACE(v->name, name);
if (getuid() == 0)
(void)asprintf(&v->workdir, "/tmp/__%s", name);
assert(asprintf(&v->workdir, "/tmp/__%s", name) >= 0);
else
(void)asprintf(&v->workdir, "/tmp/__%s.%d", name, getuid());
assert(asprintf(&v->workdir, "/tmp/__%s.%d", name, getuid()) >= 0);
AN(v->workdir);
(void)asprintf(&c, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir);
assert(asprintf(&c, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir) >= 0);
AN(c);
AZ(system(c));
v->vl = vtc_logopen(name);
......
......@@ -47,6 +47,7 @@ SVNID("$Id$")
#include "vcc_priv.h"
#include "vcc_compile.h"
#include "libvarnish.h"
#include "compat/vasprintf.h"
struct acl_e {
VTAILQ_ENTRY(acl_e) list;
......@@ -472,8 +473,8 @@ vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl)
VTAILQ_INIT(&tl->acl);
tcond = tl->t->tok;
vcc_NextToken(tl);
asprintf(&acln, "%u", tl->cnt);
assert(acln != NULL);
assert(asprintf(&acln, "%u", tl->cnt) > 0);
AN(acln);
vcc_acl_entry(tl);
vcc_acl_emit(tl, acln, 1);
Fb(tl, 1, "%smatch_acl_anon_%s(sp, %s)\n",
......@@ -504,8 +505,8 @@ vcc_Acl(struct tokenlist *tl)
vcc_NextToken(tl);
vcc_AddDef(tl, an, R_ACL);
asprintf(&acln, "%.*s", PF(an));
assert(acln != NULL);
assert(asprintf(&acln, "%.*s", PF(an)) > 0);
AN(acln);
ExpectErr(tl, '{');
vcc_NextToken(tl);
......
......@@ -40,6 +40,7 @@ SVNID("$Id$")
#include "vcc_priv.h"
#include "vcc_compile.h"
#include "libvarnish.h"
#include "compat/vasprintf.h"
/*--------------------------------------------------------------------*/
......@@ -64,13 +65,13 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
v->fmt = STRING;
v->hdr = vh->hdr;
v->methods = vh->methods;
asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
assert(asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
AN(p);
TlFree(tl, p);
v->rname = p;
asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
assert(asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
AN(p);
TlFree(tl, p);
v->lname = p;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment