Commit 69897c6b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Eliminate a NULL pointer issue with empty (apart from comments and

whitespace) testfiles.

Spotted by:	Coverity
parent fc6790d4
......@@ -428,6 +428,50 @@ dns_works(void)
return (1);
}
/**********************************************************************
* Main
*/
static int
read_file(const char *fn, int ntest)
{
struct vtc_tst *tp;
char *p;
p = VFIL_readfile(NULL, fn, NULL);
if (p == NULL) {
fprintf(stderr, "Cannot stat file \"%s\": %s\n",
fn, strerror(errno));
return (2);
}
for (;p != NULL && *p != '\0'; p++) {
if (vct_islws(*p))
continue;
if (*p != '#')
break;
p = strchr(p, '\n');
}
if (p == NULL || *p == '\0') {
fprintf(stderr, "File \"%s\" has no content.\n", fn);
return (2);
}
if (strncmp(p, "varnishtest", 11) || !isspace(p[11])) {
fprintf(stderr,
"File \"%s\" doesn't start with 'varnishtest'\n",
fn);
return(2);
}
ALLOC_OBJ(tp, TST_MAGIC);
AN(tp);
tp->filename = fn;
tp->script = p;
tp->ntodo = ntest;
VTAILQ_INSERT_TAIL(&tst_head, tp, list);
return(0);
}
/**********************************************************************
* Main
*/
......@@ -437,8 +481,6 @@ main(int argc, char * const *argv)
{
int ch, i;
int ntest = 1; /* Run tests this many times */
struct vtc_tst *tp;
char *p;
uintmax_t bufsiz;
/* Default names of programs */
......@@ -523,40 +565,10 @@ main(int argc, char * const *argv)
argv += optind;
for (;argc > 0; argc--, argv++) {
p = VFIL_readfile(NULL, *argv, NULL);
if (p == NULL) {
fprintf(stderr, "Cannot stat file \"%s\": %s\n",
*argv, strerror(errno));
if (vtc_continue)
continue;
exit(2);
}
while (1) {
if (vct_islws(*p)) {
p++;
continue;
}
if (*p == '#') {
if ((p = strchr(p, '\n')))
p++;
continue;
}
break;
}
if (strncmp(p, "varnishtest", 11) || !isspace(p[11])) {
fprintf(stderr, "File \"%s\" doesn't start with 'varnishtest'\n",
*argv);
if (vtc_continue)
continue;
if (!read_file(*argv, ntest))
continue;
if (!vtc_continue)
exit(2);
}
ALLOC_OBJ(tp, TST_MAGIC);
AN(tp);
tp->filename = *argv;
tp->script = p;
tp->ntodo = ntest;
VTAILQ_INSERT_TAIL(&tst_head, tp, list);
}
feature_dns = dns_works();
......
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