diff --git a/common/common.h b/common/common.h index f2949ebc..ae6dc265 100644 --- a/common/common.h +++ b/common/common.h @@ -139,7 +139,6 @@ enum { #define FKO_DEFAULT_PORT 62201 #define DEFAULT_NAT_PORT 55000 #define MIN_HIGH_PORT 10000 /* sensible minimum for SPA dest port */ -#define MAX_PORT 65535 #define MAX_SERVER_STR_LEN 50 #define MAX_ICMP_TYPE 40 #define MAX_ICMP_CODE 15 diff --git a/lib/fko_limits.h b/lib/fko_limits.h index 040c71d0..3b0474a7 100644 --- a/lib/fko_limits.h +++ b/lib/fko_limits.h @@ -58,8 +58,9 @@ #define MAX_IPV4_STR_LEN 16 #define MIN_IPV4_STR_LEN 7 -#define MAX_PROTO_STR_LEN 4 /* tcp, udp, icmp for now */ -#define MAX_PORT_STR_LEN 5 +#define MAX_PROTO_STR_LEN 4 /* tcp, udp, icmp for now */ +#define MAX_PORT_STR_LEN 5 +#define MAX_PORT 65535 /* Misc. */ diff --git a/lib/fko_message.c b/lib/fko_message.c index a7e22388..e9e3a046 100644 --- a/lib/fko_message.c +++ b/lib/fko_message.c @@ -75,8 +75,10 @@ have_allow_ip(const char *msg) static int have_port(const char *msg) { - const char *ndx = msg; - int startlen = strnlen(msg, MAX_SPA_MESSAGE_SIZE), port_str_len = 0; + const char *ndx = msg; + char port_str[MAX_PORT_STR_LEN+1] = {0}; + int startlen = strnlen(msg, MAX_SPA_MESSAGE_SIZE); + int port_str_len=0, i=0, is_err; if(startlen == MAX_SPA_MESSAGE_SIZE) return(FKO_ERROR_INVALID_DATA_MESSAGE_PORT_MISSING); @@ -91,8 +93,15 @@ have_port(const char *msg) port_str_len++; if((isdigit(*ndx) == 0) || (port_str_len > MAX_PORT_STR_LEN)) return(FKO_ERROR_INVALID_SPA_ACCESS_MSG); + port_str[i] = *ndx; ndx++; + i++; } + port_str[i] = '\0'; + + strtol_wrapper(port_str, 1, MAX_PORT, NO_EXIT_UPON_ERR, &is_err); + if(is_err != FKO_SUCCESS) + return(FKO_ERROR_INVALID_SPA_ACCESS_MSG); return FKO_SUCCESS; }