[libfko] validate MAX_PORT integer value for SPA messages

This commit is contained in:
Michael Rash
2014-10-25 08:42:14 -04:00
parent 58d47cb385
commit 837f7780fe
3 changed files with 14 additions and 5 deletions
-1
View File
@@ -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
+3 -2
View File
@@ -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.
*/
+11 -2
View File
@@ -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;
}