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, ...)
}
/**********************************************************************
* 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
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];
struct vsb *token_exp[MAX_TOKENS];
char *p, *q, *f;
char *p, *q, *f, *buf;
int nest_brace;
int tn;
const struct cmds *cp;
assert(buf != NULL);
AN(spec);
buf = strdup(spec);
AN(buf);
for (p = buf; *p != '\0'; p++) {
if (vtc_error || vtc_stop)
break;
......@@ -359,8 +367,9 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl)
if (NULL == strstr(token_s[tn], "${"))
continue;
token_exp[tn] = macro_expand(vl, token_s[tn]);
if (vtc_error)
if (vtc_error) {
return;
}
token_s[tn] = VSB_data(token_exp[tn]);
token_e[tn] = strchr(token_s[tn], '\0');
}
......@@ -619,7 +628,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen)
{
unsigned old_err;
char *p;
FILE *f;
struct extmacro *m;
......@@ -658,11 +666,8 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
vtc_stop = 0;
vtc_log(vltop, 1, "TEST %s starting", fn);
p = strdup(script);
AN(p);
vtc_thread = pthread_self();
parse_string(p, cmds, NULL, vltop);
parse_string(script, cmds, NULL, vltop);
old_err = vtc_error;
vtc_stop = 1;
vtc_log(vltop, 1, "RESETTING after %s", fn);
......
......@@ -54,7 +54,7 @@ struct cmds {
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);
cmd_f cmd_delay;
......
......@@ -1256,7 +1256,6 @@ cmd_http_loop(CMD_ARGS)
{
struct http *hp;
unsigned n, m;
char *s;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
AN(av[1]);
......@@ -1265,9 +1264,7 @@ cmd_http_loop(CMD_ARGS)
n = strtoul(av[1], NULL, 0);
for (m = 1 ; m <= n; m++) {
vtc_log(vl, 4, "Loop #%u", m);
s = strdup(av[2]);
AN(s);
parse_string(s, cmd, hp, vl);
parse_string(av[2], cmd, hp, vl);
}
}
......@@ -1331,7 +1328,6 @@ int
http_process(struct vtclog *vl, const char *spec, int sock, int *sfd)
{
struct http *hp;
char *s;
int retval;
(void)sfd;
......@@ -1349,10 +1345,7 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd)
AN(hp->rxbuf);
AN(hp->vsb);
s = strdup(spec);
AN(s);
parse_string(s, http_cmds, hp, vl);
free(s);
parse_string(spec, http_cmds, hp, vl);
retval = hp->fd;
VSB_delete(hp->vsb);
free(hp->rxbuf);
......
......@@ -453,16 +453,11 @@ static const struct cmds logexp_cmds[] = {
static void
logexp_spec(struct logexp *le, const char *spec)
{
char *s;
CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC);
logexp_delete_tests(le);
s = strdup(spec);
AN(s);
parse_string(s, logexp_cmds, le, le->vl);
free(s);
parse_string(spec, logexp_cmds, le, le->vl);
}
void
......
......@@ -61,9 +61,10 @@ sema_new(char *name, struct vtclog *vl)
ALLOC_OBJ(r, SEMA_MAGIC);
AN(r);
r->name = name;
AN(name);
if (*name != 'r')
vtc_log(vl, 0, "Sema name must start with 'r' (%s)", name);
r->name = name;
AZ(pthread_mutex_init(&r->mtx, NULL));
AZ(pthread_cond_init(&r->cond, NULL));
......
......@@ -75,7 +75,6 @@ struct varnish {
struct VSM_data *vd; /* vsc use */
unsigned vsl_tag_count[256];
unsigned vsl_sleep;
};
#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