Commit ecddbee0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the necessary strdup() into parse_string and comment that we

deliberately leak that copy, so the cmd functions we call don't
have to worry about strdup'ing individual arguments.
parent aeb18904
...@@ -255,20 +255,28 @@ extmacro_def(const char *name, const char *fmt, ...) ...@@ -255,20 +255,28 @@ extmacro_def(const char *name, const char *fmt, ...)
} }
/********************************************************************** /**********************************************************************
* Execute a file * Parse a string
*
* We make a copy of the string and deliberately leak it, so that all
* the cmd functions we call don't have to strdup(3) all over the place.
*
* Static checkers like Coverity may bitch about this, but we don't care.
*/ */
void void
parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl) parse_string(const char *spec, const struct cmds *cmd, void *priv,
struct vtclog *vl)
{ {
char *token_s[MAX_TOKENS], *token_e[MAX_TOKENS]; char *token_s[MAX_TOKENS], *token_e[MAX_TOKENS];
struct vsb *token_exp[MAX_TOKENS]; struct vsb *token_exp[MAX_TOKENS];
char *p, *q, *f; char *p, *q, *f, *buf;
int nest_brace; int nest_brace;
int tn; int tn;
const struct cmds *cp; const struct cmds *cp;
assert(buf != NULL); AN(spec);
buf = strdup(spec);
AN(buf);
for (p = buf; *p != '\0'; p++) { for (p = buf; *p != '\0'; p++) {
if (vtc_error || vtc_stop) if (vtc_error || vtc_stop)
break; break;
...@@ -359,8 +367,9 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl) ...@@ -359,8 +367,9 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl)
if (NULL == strstr(token_s[tn], "${")) if (NULL == strstr(token_s[tn], "${"))
continue; continue;
token_exp[tn] = macro_expand(vl, token_s[tn]); token_exp[tn] = macro_expand(vl, token_s[tn]);
if (vtc_error) if (vtc_error) {
return; return;
}
token_s[tn] = VSB_data(token_exp[tn]); token_s[tn] = VSB_data(token_exp[tn]);
token_e[tn] = strchr(token_s[tn], '\0'); token_e[tn] = strchr(token_s[tn], '\0');
} }
...@@ -619,7 +628,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir, ...@@ -619,7 +628,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen) char *logbuf, unsigned loglen)
{ {
unsigned old_err; unsigned old_err;
char *p;
FILE *f; FILE *f;
struct extmacro *m; struct extmacro *m;
...@@ -658,11 +666,8 @@ exec_file(const char *fn, const char *script, const char *tmpdir, ...@@ -658,11 +666,8 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
vtc_stop = 0; vtc_stop = 0;
vtc_log(vltop, 1, "TEST %s starting", fn); vtc_log(vltop, 1, "TEST %s starting", fn);
p = strdup(script);
AN(p);
vtc_thread = pthread_self(); vtc_thread = pthread_self();
parse_string(p, cmds, NULL, vltop); parse_string(script, cmds, NULL, vltop);
old_err = vtc_error; old_err = vtc_error;
vtc_stop = 1; vtc_stop = 1;
vtc_log(vltop, 1, "RESETTING after %s", fn); vtc_log(vltop, 1, "RESETTING after %s", fn);
......
...@@ -54,7 +54,7 @@ struct cmds { ...@@ -54,7 +54,7 @@ struct cmds {
cmd_f *cmd; cmd_f *cmd;
}; };
void parse_string(char *buf, const struct cmds *cmd, void *priv, void parse_string(const char *spec, const struct cmds *cmd, void *priv,
struct vtclog *vl); struct vtclog *vl);
cmd_f cmd_delay; cmd_f cmd_delay;
......
...@@ -1256,7 +1256,6 @@ cmd_http_loop(CMD_ARGS) ...@@ -1256,7 +1256,6 @@ cmd_http_loop(CMD_ARGS)
{ {
struct http *hp; struct http *hp;
unsigned n, m; unsigned n, m;
char *s;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
AN(av[1]); AN(av[1]);
...@@ -1265,9 +1264,7 @@ cmd_http_loop(CMD_ARGS) ...@@ -1265,9 +1264,7 @@ cmd_http_loop(CMD_ARGS)
n = strtoul(av[1], NULL, 0); n = strtoul(av[1], NULL, 0);
for (m = 1 ; m <= n; m++) { for (m = 1 ; m <= n; m++) {
vtc_log(vl, 4, "Loop #%u", m); vtc_log(vl, 4, "Loop #%u", m);
s = strdup(av[2]); parse_string(av[2], cmd, hp, vl);
AN(s);
parse_string(s, cmd, hp, vl);
} }
} }
...@@ -1331,7 +1328,6 @@ int ...@@ -1331,7 +1328,6 @@ int
http_process(struct vtclog *vl, const char *spec, int sock, int *sfd) http_process(struct vtclog *vl, const char *spec, int sock, int *sfd)
{ {
struct http *hp; struct http *hp;
char *s;
int retval; int retval;
(void)sfd; (void)sfd;
...@@ -1349,10 +1345,7 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd) ...@@ -1349,10 +1345,7 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd)
AN(hp->rxbuf); AN(hp->rxbuf);
AN(hp->vsb); AN(hp->vsb);
s = strdup(spec); parse_string(spec, http_cmds, hp, vl);
AN(s);
parse_string(s, http_cmds, hp, vl);
free(s);
retval = hp->fd; retval = hp->fd;
VSB_delete(hp->vsb); VSB_delete(hp->vsb);
free(hp->rxbuf); free(hp->rxbuf);
......
...@@ -453,16 +453,11 @@ static const struct cmds logexp_cmds[] = { ...@@ -453,16 +453,11 @@ static const struct cmds logexp_cmds[] = {
static void static void
logexp_spec(struct logexp *le, const char *spec) logexp_spec(struct logexp *le, const char *spec)
{ {
char *s;
CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC); CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC);
logexp_delete_tests(le); logexp_delete_tests(le);
s = strdup(spec); parse_string(spec, logexp_cmds, le, le->vl);
AN(s);
parse_string(s, logexp_cmds, le, le->vl);
free(s);
} }
void void
......
...@@ -61,9 +61,10 @@ sema_new(char *name, struct vtclog *vl) ...@@ -61,9 +61,10 @@ sema_new(char *name, struct vtclog *vl)
ALLOC_OBJ(r, SEMA_MAGIC); ALLOC_OBJ(r, SEMA_MAGIC);
AN(r); AN(r);
r->name = name; AN(name);
if (*name != 'r') if (*name != 'r')
vtc_log(vl, 0, "Sema name must start with 'r' (%s)", name); vtc_log(vl, 0, "Sema name must start with 'r' (%s)", name);
r->name = name;
AZ(pthread_mutex_init(&r->mtx, NULL)); AZ(pthread_mutex_init(&r->mtx, NULL));
AZ(pthread_cond_init(&r->cond, NULL)); AZ(pthread_cond_init(&r->cond, NULL));
......
...@@ -75,7 +75,6 @@ struct varnish { ...@@ -75,7 +75,6 @@ struct varnish {
struct VSM_data *vd; /* vsc use */ struct VSM_data *vd; /* vsc use */
unsigned vsl_tag_count[256]; unsigned vsl_tag_count[256];
unsigned vsl_sleep;
}; };
#define NONSENSE "%XJEIFLH|)Xspa8P" #define NONSENSE "%XJEIFLH|)Xspa8P"
......
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