stun

simple point to point tunnel
git clone git://git.2f30.org/stun.git
Log | Files | Refs | README

commit 30287437842e19234989ef96b0cbb8f203e62255
parent e62e628a67f9b242c749f068ddc0ba477fd97b6d
Author: sin <sin@2f30.org>
Date:   Sat Apr 30 15:43:36 +0100

Pull out stat() to make pushfile() balanced with popfile()

Diffstat:
parse.y | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/parse.y b/parse.y @@ -96,8 +96,15 @@ optnl_l : ; include : INCLUDE STRING { + struct stat sb; struct file *nfile; + if (stat($2, &sb) == 0 && sb.st_mode & 007) { + yyerror("%s: shouldn't be readable by others", $2); + free($2); + YYERROR; + } + if (!(nfile = pushfile($2))) { yyerror("failed to include %s", $2); free($2); @@ -580,14 +587,8 @@ nodigits: static struct file * pushfile(const char *name) { - struct stat sb; struct file *nfile; - if (stat(name, &sb) == 0 && sb.st_mode & 007) { - logerrx("%s: shouldn't be readable by others", name); - return NULL; - } - if (!(nfile = calloc(1, sizeof(struct file)))) return NULL; if (!(nfile->name = strdup(name))) { @@ -634,12 +635,18 @@ resetnetconfig(struct netcfg *n) int parseconf(const char *filename) { + struct stat sb; struct netcfg *n, *ntmp; int errors = 0; TAILQ_INIT(&netcfgs); resetnetconfig(&curnet); + if (stat(filename, &sb) == 0 && sb.st_mode & 007) { + logerrx("%s: shouldn't be readable by others", filename); + return -1; + } + if (!(file = pushfile(filename))) { logerrx("failed to open %s", filename); return -1;