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>
This commit is contained in:
parent
0d1886dca0
commit
3ede07aac9
3 changed files with 9 additions and 8 deletions
11
conf.c
11
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,
|
static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
struct port_fwd *fwd)
|
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;
|
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 };
|
uint8_t exclude[PORT_BITMAP_SIZE] = { 0 };
|
||||||
char buf[BUFSIZ], *sep, *spec, *p;
|
char buf[BUFSIZ], *sep, *spec, *p;
|
||||||
sa_family_t af = AF_UNSPEC;
|
sa_family_t af = AF_UNSPEC;
|
||||||
|
unsigned port;
|
||||||
|
|
||||||
if (!strcmp(optarg, "none")) {
|
if (!strcmp(optarg, "none")) {
|
||||||
if (fwd->mode)
|
if (fwd->mode)
|
||||||
|
@ -204,11 +205,11 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
port = strtol(p, &sep, 10);
|
port = strtoul(p, &sep, 10);
|
||||||
if (sep == p)
|
if (sep == p)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (port < 0 || port > USHRT_MAX || errno)
|
if (port > USHRT_MAX || errno)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
switch (*sep) {
|
switch (*sep) {
|
||||||
|
@ -271,11 +272,11 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
port = strtol(p, &sep, 10);
|
port = strtoul(p, &sep, 10);
|
||||||
if (sep == p)
|
if (sep == p)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (port < 0 || port > USHRT_MAX || errno)
|
if (port > USHRT_MAX || errno)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
/* -p 22
|
/* -p 22
|
||||||
|
|
4
tcp.c
4
tcp.c
|
@ -3182,7 +3182,7 @@ void tcp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
||||||
static int tcp_sock_init_ns(void *arg)
|
static int tcp_sock_init_ns(void *arg)
|
||||||
{
|
{
|
||||||
struct ctx *c = (struct ctx *)arg;
|
struct ctx *c = (struct ctx *)arg;
|
||||||
int port;
|
unsigned port;
|
||||||
|
|
||||||
ns_enter(c);
|
ns_enter(c);
|
||||||
|
|
||||||
|
@ -3381,7 +3381,7 @@ struct tcp_port_rebind_arg {
|
||||||
static int tcp_port_rebind(void *arg)
|
static int tcp_port_rebind(void *arg)
|
||||||
{
|
{
|
||||||
struct tcp_port_rebind_arg *a = (struct tcp_port_rebind_arg *)arg;
|
struct tcp_port_rebind_arg *a = (struct tcp_port_rebind_arg *)arg;
|
||||||
int port;
|
unsigned port;
|
||||||
|
|
||||||
if (a->bind_in_ns) {
|
if (a->bind_in_ns) {
|
||||||
ns_enter(a->c);
|
ns_enter(a->c);
|
||||||
|
|
2
udp.c
2
udp.c
|
@ -1193,7 +1193,7 @@ void udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
||||||
int udp_sock_init_ns(void *arg)
|
int udp_sock_init_ns(void *arg)
|
||||||
{
|
{
|
||||||
struct ctx *c = (struct ctx *)arg;
|
struct ctx *c = (struct ctx *)arg;
|
||||||
int dst;
|
unsigned dst;
|
||||||
|
|
||||||
if (ns_enter(c))
|
if (ns_enter(c))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue