From 606f52e77d930f982bf9dd2c205228023330a93a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 12 Aug 2013 17:51:57 +0200 Subject: config: check (and fix) some integer limits --- src/config.l | 16 +++++++++++++++- src/config.y | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/config.l b/src/config.l index 295352f..c9f25d8 100644 --- a/src/config.l +++ b/src/config.l @@ -55,7 +55,21 @@ %} { -[0-9]+ { UPDATE_LOCATION; yylval->num = atoi(yytext); BEGIN(NEEDSPACE); return TOK_INTEGER; } +[0-9]+ { + char *endptr; + + UPDATE_LOCATION; + + yylval->uint64 = strtoull(yytext, &endptr, 10); + if (*endptr) { + yylval->error = "invalid integer constant"; + return -1; + } + + + BEGIN(NEEDSPACE); + return TOK_UINT; +} interface { TOKEN(TOK_INTERFACE); } bind { TOKEN(TOK_BIND); } diff --git a/src/config.y b/src/config.y index 16f3437..deaa100 100644 --- a/src/config.y +++ b/src/config.y @@ -39,7 +39,8 @@ } %union { - int num; + uint64_t uint64; + int64_t int64; fastd_string_stack_t *str; bool boolean; fastd_tristate_t tristate; @@ -54,7 +55,7 @@ %token START_PEER_GROUP_CONFIG %token START_PEER_CONFIG -%token TOK_INTEGER +%token TOK_UINT %token TOK_STRING %token TOK_INTERFACE @@ -121,6 +122,7 @@ %code { #include + #include #include #include @@ -128,19 +130,19 @@ } -%type maybe_log_level -%type log_level -%type port +%type maybe_log_level +%type log_level +%type port %type boolean -%type maybe_port +%type maybe_port %type maybe_as -%type maybe_af +%type maybe_af %type maybe_float %type bind_address %type maybe_bind_interface -%type maybe_bind_default -%type bind_default -%type drop_capabilities_enabled +%type maybe_bind_default +%type bind_default +%type drop_capabilities_enabled %type autobool %% @@ -308,7 +310,14 @@ bind_default: } ; -mtu: TOK_INTEGER { conf->mtu = $1; } +mtu: TOK_UINT { + if ($1 > 65535) { + fastd_config_error(&@$, ctx, conf, filename, depth, "invalid MTU"); + YYERROR; + } + + conf->mtu = $1; + } ; pmtu: autobool { conf->pmtu = $1; } @@ -472,7 +481,12 @@ peer_group_after: } ; -peer_limit: TOK_INTEGER { +peer_limit: TOK_UINT { + if ($1 > INT_MAX) { + fastd_config_error(&@$, ctx, conf, filename, depth, "invalid peer limit"); + YYERROR; + } + conf->peer_group->max_connections = $1; } ; @@ -529,8 +543,8 @@ colon_or_port: ':' | TOK_PORT ; -port: colon_or_port TOK_INTEGER { - if ($2 < 0 || $2 > 65635) { +port: colon_or_port TOK_UINT { + if ($2 > 65535) { fastd_config_error(&@$, ctx, conf, filename, depth, "invalid port"); YYERROR; } -- cgit v1.2.3