require absolute paths in config file

This commit is contained in:
Omar Polo 2021-02-01 11:08:57 +00:00
parent bcf5d929e6
commit e17642a7bb
2 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2021-02-01 Omar Polo <op@omarpolo.com>
* parse.y (servopt): require absolute paths in config file
2021-01-31 Omar Polo <op@omarpolo.com>
* gmid.c (main): cgi scripts now have only std{in,out,err} open

15
parse.y
View File

@ -40,6 +40,7 @@ const char *config_path;
void yyerror(const char*);
int parse_portno(const char*);
void parse_conf(const char*);
char *ensure_absolute_path(char*);
%}
@ -111,9 +112,9 @@ servopts : /* empty */
| servopts servopt
;
servopt : TCERT TSTRING { host->cert = $2; }
| TKEY TSTRING { host->key = $2; }
| TROOT TSTRING { host->dir = $2; }
servopt : TCERT TSTRING { host->cert = ensure_absolute_path($2); }
| TKEY TSTRING { host->key = ensure_absolute_path($2); }
| TROOT TSTRING { host->dir = ensure_absolute_path($2); }
| TCGI TSTRING {
host->cgi = $2;
/* drop the starting '/', if any */
@ -191,3 +192,11 @@ parse_conf(const char *path)
if (goterror)
exit(1);
}
char *
ensure_absolute_path(char *path)
{
if (path == NULL || *path != '/')
yyerror("not an absolute path");
return path;
}