aboutgitcodebugslistschat
path: root/conf.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-24 19:08:21 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-24 14:48:35 +0200
commit3ede07aac96eababe3b1c335058e851a9951d17d (patch)
tree284773ba582b574635a6186b16646ed7e78b1764 /conf.c
parent0d1886dca01df2d12697422c09a8d8f76dff0400 (diff)
downloadpasst-3ede07aac96eababe3b1c335058e851a9951d17d.tar
passt-3ede07aac96eababe3b1c335058e851a9951d17d.tar.gz
passt-3ede07aac96eababe3b1c335058e851a9951d17d.tar.bz2
passt-3ede07aac96eababe3b1c335058e851a9951d17d.tar.lz
passt-3ede07aac96eababe3b1c335058e851a9951d17d.tar.xz
passt-3ede07aac96eababe3b1c335058e851a9951d17d.tar.zst
passt-3ede07aac96eababe3b1c335058e851a9951d17d.zip
Treat port numbers as unsigned
Port numbers are unsigned values, but we're storing them in (signed) int variables in some places. This isn't actually harmful, because int is large enough to hold the entire range of ports. However in places we don't want to use an in_port_t (usually to avoid overflow on the last iteration of a loop) it makes more conceptual sense to use an unsigned int. This will also avoid some problems with later cleanups. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/conf.c b/conf.c
index 6bb4c93..4e86508 100644
--- a/conf.c
+++ b/conf.c
@@ -118,11 +118,12 @@ static int get_bound_ports_ns(void *arg)
static int conf_ports(const struct ctx *c, char optname, const char *optarg,
struct port_fwd *fwd)
{
- int start_src, end_src, start_dst, end_dst, exclude_only = 1, i, port;
char addr_buf[sizeof(struct in6_addr)] = { 0 }, *addr = addr_buf;
+ int start_src, end_src, start_dst, end_dst, exclude_only = 1, i;
uint8_t exclude[PORT_BITMAP_SIZE] = { 0 };
char buf[BUFSIZ], *sep, *spec, *p;
sa_family_t af = AF_UNSPEC;
+ unsigned port;
if (!strcmp(optarg, "none")) {
if (fwd->mode)
@@ -204,11 +205,11 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
p++;
errno = 0;
- port = strtol(p, &sep, 10);
+ port = strtoul(p, &sep, 10);
if (sep == p)
break;
- if (port < 0 || port > USHRT_MAX || errno)
+ if (port > USHRT_MAX || errno)
goto bad;
switch (*sep) {
@@ -271,11 +272,11 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
break;
errno = 0;
- port = strtol(p, &sep, 10);
+ port = strtoul(p, &sep, 10);
if (sep == p)
break;
- if (port < 0 || port > USHRT_MAX || errno)
+ if (port > USHRT_MAX || errno)
goto bad;
/* -p 22