aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--gmid.c12
-rw-r--r--gmid.h1
-rw-r--r--parse.y26
3 files changed, 24 insertions, 15 deletions
diff --git a/gmid.c b/gmid.c
index 6f349a6..5d6e1cc 100644
--- a/gmid.c
+++ b/gmid.c
@@ -532,6 +532,18 @@ setup_configless(int argc, char **argv, const char *cgi)
imsg_flush(&logibuf);
}
+static 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;
+}
+
int
main(int argc, char **argv)
{
diff --git a/gmid.h b/gmid.h
index 97870df..9a06656 100644
--- a/gmid.h
+++ b/gmid.h
@@ -317,7 +317,6 @@ void free_config(void);
void drop_priv(void);
void yyerror(const char*, ...);
-int parse_portno(const char*);
void parse_conf(const char*);
int cmdline_symset(char *);
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)