Commit Diff
Diff:
e3b2a0f8de7210c4d403cf4c30d956c34d8c9353
391825e3604deef4c9dc3267dc2b6c89fc79958a
Commit:
391825e3604deef4c9dc3267dc2b6c89fc79958a
Tree:
5a97c2574ee71812dce79389469355a290afc08a
Author:
Omar Polo <op@omarpolo.com>
Date:
Fri Jul 9 13:06:58 2021 UTC
Message:
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.
commit - e3b2a0f8de7210c4d403cf4c30d956c34d8c9353
commit + 391825e3604deef4c9dc3267dc2b6c89fc79958a
blob - 6f349a6e9c8f799f41fbb923a691a51e01ca22a6
blob + 5d6e1ccfe673ffdfe180f6d061a6cd7ed0266fe3
--- gmid.c
+++ gmid.c
@@ -530,6 +530,18 @@ setup_configless(int argc, char **argv, const char *cg
imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
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
blob - 97870df22dc9188ddc84f311a0733f6da6524499
blob + 9a066562252414ad448170053460acc526f27e28
--- gmid.h
+++ gmid.h
@@ -317,7 +317,6 @@ int parse_portno(const char*);
void drop_priv(void);
void yyerror(const char*, ...);
-int parse_portno(const char*);
void parse_conf(const char*);
int cmdline_symset(char *);
blob - b656f6b43d3825a1462e57e84c751704376a0f2d
blob + 35a918a70de6d82089057c1cfd41193faadf5d8d
--- parse.y
+++ parse.y
@@ -78,11 +78,11 @@ int parse_portno(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)
@@ -862,18 +862,6 @@ new_location(void)
l->dirfd = -1;
l->fcgi = -1;
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 *
@@ -924,6 +912,16 @@ check_prefork_num(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)
Omar Polo