aboutsummaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-07-09 13:06:58 +0000
committerOmar Polo <op@omarpolo.com>2021-07-09 13:06:58 +0000
commit391825e3604deef4c9dc3267dc2b6c89fc79958a (patch)
tree5a97c2574ee71812dce79389469355a290afc08a /parse.y
parente3b2a0f8de7210c4d403cf4c30d956c34d8c9353 (diff)
move parse_portno to gmid.c
it's used only to parse the -p flag. While there add check_port_num to check the range for the port.
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y26
1 files changed, 12 insertions, 14 deletions
diff --git a/parse.y b/parse.y
index b656f6b..35a918a 100644
--- a/parse.y
+++ b/parse.y
@@ -78,11 +78,11 @@ char *symget(const char *);
struct vhost *new_vhost(void);
struct location *new_location(void);
-int parse_portno(const char*);
char *ensure_absolute_path(char*);
int check_block_code(int);
char *check_block_fmt(char*);
int check_strip_no(int);
+int check_port_num(int);
int check_prefork_num(int);
void advance_loc(void);
void only_once(const void*, const char*);
@@ -190,7 +190,7 @@ option : TCHROOT string { conf.chroot = $2; }
add_mime(&conf.mime, $2, $3);
}
| TMAP string TTOEXT string { add_mime(&conf.mime, $2, $4); }
- | TPORT NUM { conf.port = $2; }
+ | TPORT NUM { conf.port = check_port_num($2); }
| TPREFORK NUM { conf.prefork = check_prefork_num($2); }
| TPROTOCOLS string {
if (tls_config_parse_protocols(&conf.protos, $2) == -1)
@@ -864,18 +864,6 @@ new_location(void)
return l;
}
-int
-parse_portno(const char *p)
-{
- const char *errstr;
- int n;
-
- n = strtonum(p, 0, UINT16_MAX, &errstr);
- if (errstr != NULL)
- yyerror("port number is %s: %s", errstr, p);
- return n;
-}
-
char *
ensure_absolute_path(char *path)
{
@@ -924,6 +912,16 @@ check_strip_no(int n)
}
int
+check_port_num(int n)
+{
+ if (n <= 0 || n >= UINT16_MAX)
+ yyerror("port number is %s: %d",
+ n <= 0 ? "too small" : "too large",
+ n);
+ return n;
+}
+
+int
check_prefork_num(int n)
{
if (n <= 0 || n >= PROC_MAX)