From: "plaisthos (Code Review)" Date: Sun, 26 Jan 2025 15:18:49 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <27f67244524f6a9ea76ad27a30ec2363ad44835a-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="uf7qQAjlaBg="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Print warnings/errors when numerical parameters cannot be parsed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --uf7qQAjlaBg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello flichtenheld, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/873?usp=3Demail to look at the new patch set (#4). Change subject: Print warnings/errors when numerical parameters cannot be p= arsed ...................................................................... Print warnings/errors when numerical parameters cannot be parsed Using the atoi method is a best effort method that parses as much of the input string as possible as integer and ignores the rest or return 0 if the string cannot be parsed. This is lead to unexpected results. Change the behaviour by printing a warning in these cases instead. When parsing a configuration, these warnings will error out since the msglevel is M_USAGE in this case. Example: ./src/openvpn/openvpn --resolv-retry 198jj Options error: Cannot parse argument '198jj' as non-negative integer Reported-By: Anqi Chen Reported-By: Cristina Nita-Rotaru Change-Id: Ie1e2eb54d516b3ae87c5ca56fe8edd77ee2be4de Signed-off-by: Arne Schwabe --- M src/openvpn/options.c 1 file changed, 129 insertions(+), 78 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/73/873/4 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index bd5c056..69b0148 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -5014,11 +5014,62 @@ } #endif -static int -positive_atoi(const char *str) +/** Checks if the string is a valid integer by checking if it can be + * converted to an integer */ +static bool +valid_integer(const char *str, bool positive) { - const int i =3D atoi(str); - return i < 0 ? 0 : i; + char *endptr; + long long i =3D strtoll(str, &endptr, 10); + + if (i < INT_MIN || (positive && i < 0) || *endptr !=3D '\0' || i > INT= _MAX) + { + return false + } + else + { + return true; + } +} + + +/** + * Converts a str to a positive number if the string represents a postive + * integer number. Otherwise print a warning with msglevel and return 0 + */ +static int +positive_atoi(const char *str, int msglevel) +{ + char *endptr; + long long i =3D strtoll(str, &endptr, 10); + + if (i < 0 || *endptr !=3D '\0' || i > INT_MAX) + { + msg(msglevel, "Cannot parse argument '%s' as non-negative integer", + str); + i =3D 0; + } + + return (int) i; +} + +/** + * Converts a str to an integer if the string can be represented as an + * integer number. Otherwise print a warning with msglevel and return 0 + */ +static int +atoi_warn(const char *str, int msglevel) +{ + char *endptr; + long long i =3D strtoll(str, &endptr, 10); + + if (i < INT_MIN || *endptr !=3D '\0' || i > INT_MAX) + { + msg(msglevel, "Cannot parse argument '%s' as integer", str); + i =3D 0; + } + + return (int) i; } #ifdef _WIN32 /* This function is only used when compiling on Windows */ @@ -6043,7 +6094,7 @@ int cache; VERIFY_PERMISSION(OPT_P_GENERAL); - cache =3D atoi(p[1]); + cache =3D atoi_warn(p[1], msglevel); if (cache < 1) { msg(msglevel, "--management-log-cache parameter is out of rang= e"); @@ -6355,7 +6406,7 @@ } else { - options->resolve_retry_seconds =3D positive_atoi(p[1]); + options->resolve_retry_seconds =3D positive_atoi(p[1], msgleve= l); } } else if ((streq(p[0], "preresolve") || streq(p[0], "ip-remote-hint")) = && !p[2]) @@ -6372,7 +6423,7 @@ else if (streq(p[0], "connect-retry") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); - options->ce.connect_retry_seconds =3D positive_atoi(p[1]); + options->ce.connect_retry_seconds =3D positive_atoi(p[1], msglevel= ); /* * Limit the base value of retry wait interval to 16 bits to avoid * overflow when scaled up for exponential backoff @@ -6387,19 +6438,19 @@ if (p[2]) { options->ce.connect_retry_seconds_max =3D - max_int(positive_atoi(p[2]), options->ce.connect_retry_sec= onds); + max_int(positive_atoi(p[2], msglevel), options->ce.connect= _retry_seconds); } } else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-t= imeout")) && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); - options->ce.connect_timeout =3D positive_atoi(p[1]); + options->ce.connect_timeout =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "connect-retry-max") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); - options->connect_retry_max =3D positive_atoi(p[1]); + options->connect_retry_max =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "ipchange") && p[1]) { @@ -6422,7 +6473,7 @@ else if (streq(p[0], "gremlin") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL); - options->gremlin =3D positive_atoi(p[1]); + options->gremlin =3D positive_atoi(p[1], msglevel); } #endif else if (streq(p[0], "chroot") && p[1] && !p[2]) @@ -6554,7 +6605,7 @@ else if (streq(p[0], "verb") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MESSAGES); - options->verbosity =3D positive_atoi(p[1]); + options->verbosity =3D positive_atoi(p[1], msglevel); if (options->verbosity >=3D (D_TLS_DEBUG_MED & M_DEBUG_LEVEL)) { /* We pass this flag to the SSL library to avoid @@ -6573,7 +6624,7 @@ else if (streq(p[0], "mute") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MESSAGES); - options->mute =3D positive_atoi(p[1]); + options->mute =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "errors-to-stderr") && !p[1]) { @@ -6586,7 +6637,7 @@ options->status_file =3D p[1]; if (p[2]) { - options->status_file_update_freq =3D positive_atoi(p[2]); + options->status_file_update_freq =3D positive_atoi(p[2], msgle= vel); } } else if (streq(p[0], "status-version") && p[1] && !p[2]) @@ -6594,7 +6645,7 @@ int version; VERIFY_PERMISSION(OPT_P_GENERAL); - version =3D atoi(p[1]); + version =3D atoi_warn(p[1], msglevel); if (version < 1 || version > 3) { msg(msglevel, "--status-version must be 1 to 3"); @@ -6622,17 +6673,17 @@ else if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu")) && p[1] &= & !p[2]) { VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); - options->ce.link_mtu =3D positive_atoi(p[1]); + options->ce.link_mtu =3D positive_atoi(p[1], msglevel); options->ce.link_mtu_defined =3D true; } else if (streq(p[0], "tun-mtu") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_PUSH_MTU|OPT_P_CONNECTION); - options->ce.tun_mtu =3D positive_atoi(p[1]); + options->ce.tun_mtu =3D positive_atoi(p[1], msglevel); options->ce.tun_mtu_defined =3D true; if (p[2]) { - options->ce.occ_mtu =3D positive_atoi(p[2]); + options->ce.occ_mtu =3D positive_atoi(p[2], msglevel); } else { @@ -6642,7 +6693,7 @@ else if (streq(p[0], "tun-mtu-max") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); - int max_mtu =3D positive_atoi(p[1]); + int max_mtu =3D positive_atoi(p[1], msglevel); if (max_mtu < 68 || max_mtu > 65536) { msg(msglevel, "--tun-mtu-max value '%s' is invalid", p[1]); @@ -6655,13 +6706,13 @@ else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); - options->ce.tun_mtu_extra =3D positive_atoi(p[1]); + options->ce.tun_mtu_extra =3D positive_atoi(p[1], msglevel); options->ce.tun_mtu_extra_defined =3D true; } else if (streq(p[0], "max-packet-size") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); - int maxmtu =3D positive_atoi(p[1]); + int maxmtu =3D positive_atoi(p[1], msglevel); options->ce.tls_mtu =3D constrain_int(maxmtu, TLS_CHANNEL_MTU_MIN,= TLS_CHANNEL_BUF_SIZE); if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHANNEL_BUF_SIZE) @@ -6687,7 +6738,7 @@ else if (streq(p[0], "fragment") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); - options->ce.fragment =3D positive_atoi(p[1]); + options->ce.fragment =3D positive_atoi(p[1], msglevel); if (options->ce.fragment < 68) { @@ -6718,23 +6769,23 @@ else if (streq(p[0], "nice") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_NICE); - options->nice =3D atoi(p[1]); + options->nice =3D atoi_warn(p[1], msglevel); } else if (streq(p[0], "rcvbuf") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_SOCKBUF); - options->rcvbuf =3D positive_atoi(p[1]); + options->rcvbuf =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "sndbuf") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_SOCKBUF); - options->sndbuf =3D positive_atoi(p[1]); + options->sndbuf =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "mark") && p[1] && !p[2]) { #if defined(TARGET_LINUX) && HAVE_DECL_SO_MARK VERIFY_PERMISSION(OPT_P_GENERAL); - options->mark =3D atoi(p[1]); + options->mark =3D atoi_warn(p[1], msglevel); #endif } else if (streq(p[0], "socket-flags")) @@ -6764,7 +6815,7 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); #ifdef TARGET_LINUX - options->tuntap_options.txqueuelen =3D positive_atoi(p[1]); + options->tuntap_options.txqueuelen =3D positive_atoi(p[1], msgleve= l); #else msg(msglevel, "--txqueuelen not supported on this OS"); goto err; @@ -6775,7 +6826,7 @@ int shaper; VERIFY_PERMISSION(OPT_P_SHAPER); - shaper =3D atoi(p[1]); + shaper =3D atoi_warn(p[1], msglevel); if (shaper < SHAPER_MIN || shaper > SHAPER_MAX) { msg(msglevel, "Bad shaper value, must be between %d and %d", @@ -6823,7 +6874,7 @@ else if (streq(p[0], "inactive") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_TIMER); - options->inactivity_timeout =3D positive_atoi(p[1]); + options->inactivity_timeout =3D positive_atoi(p[1], msglevel); if (p[2]) { int64_t val =3D atoll(p[2]); @@ -6841,7 +6892,7 @@ else if (streq(p[0], "session-timeout") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TIMER); - options->session_timeout =3D positive_atoi(p[1]); + options->session_timeout =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "proto") && p[1] && !p[2]) { @@ -7008,24 +7059,24 @@ else if (streq(p[0], "keepalive") && p[1] && p[2] && !p[3]) { VERIFY_PERMISSION(OPT_P_GENERAL); - options->keepalive_ping =3D atoi(p[1]); - options->keepalive_timeout =3D atoi(p[2]); + options->keepalive_ping =3D atoi_warn(p[1], msglevel); + options->keepalive_timeout =3D atoi_warn(p[2], msglevel); } else if (streq(p[0], "ping") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TIMER); - options->ping_send_timeout =3D positive_atoi(p[1]); + options->ping_send_timeout =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "ping-exit") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TIMER); - options->ping_rec_timeout =3D positive_atoi(p[1]); + options->ping_rec_timeout =3D positive_atoi(p[1], msglevel); options->ping_rec_timeout_action =3D PING_EXIT; } else if (streq(p[0], "ping-restart") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TIMER); - options->ping_rec_timeout =3D positive_atoi(p[1]); + options->ping_rec_timeout =3D positive_atoi(p[1], msglevel); options->ping_rec_timeout_action =3D PING_RESTART; } else if (streq(p[0], "ping-timer-rem") && !p[1]) @@ -7038,7 +7089,7 @@ VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_EXPLICIT_NO= TIFY); if (p[1]) { - options->ce.explicit_exit_notification =3D positive_atoi(p[1]); + options->ce.explicit_exit_notification =3D positive_atoi(p[1],= msglevel); } else { @@ -7158,7 +7209,7 @@ else if (streq(p[0], "route-metric") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_ROUTE); - options->route_default_metric =3D positive_atoi(p[1]); + options->route_default_metric =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "route-delay") && !p[3]) { @@ -7166,10 +7217,10 @@ options->route_delay_defined =3D true; if (p[1]) { - options->route_delay =3D positive_atoi(p[1]); + options->route_delay =3D positive_atoi(p[1], msglevel); if (p[2]) { - options->route_delay_window =3D positive_atoi(p[2]); + options->route_delay_window =3D positive_atoi(p[2], msglev= el); } } else @@ -7334,7 +7385,7 @@ } else if (streq(p[1], "SERVER_POLL_TIMEOUT") && p[2]) { - options->ce.connect_timeout =3D positive_atoi(p[2]); + options->ce.connect_timeout =3D positive_atoi(p[2], msglevel); } else { @@ -7366,14 +7417,14 @@ else if (streq(p[0], "script-security") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL); - script_security_set(atoi(p[1])); + script_security_set(atoi_warn(p[1], msglevel)); } else if (streq(p[0], "mssfix") && !p[3]) { VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); if (p[1]) { - int mssfix =3D positive_atoi(p[1]); + int mssfix =3D positive_atoi(p[1], msglevel); /* can be 0, but otherwise it needs to be high enough so we can * substract room for headers. */ if (mssfix !=3D 0 @@ -7556,7 +7607,7 @@ options->ifconfig_pool_persist_filename =3D p[1]; if (p[2]) { - options->ifconfig_pool_persist_refresh_freq =3D positive_atoi(= p[2]); + options->ifconfig_pool_persist_refresh_freq =3D positive_atoi(= p[2], msglevel); } } else if (streq(p[0], "ifconfig-ipv6-pool") && p[1] && !p[2]) @@ -7588,8 +7639,8 @@ int real, virtual; VERIFY_PERMISSION(OPT_P_GENERAL); - real =3D atoi(p[1]); - virtual =3D atoi(p[2]); + real =3D atoi_warn(p[1], msglevel); + virtual =3D atoi_warn(p[1], msglevel); if (real < 1 || virtual < 1) { msg(msglevel, "--hash-size sizes must be >=3D 1 (preferably a = power of 2)"); @@ -7603,8 +7654,8 @@ int cf_max, cf_per; VERIFY_PERMISSION(OPT_P_GENERAL); - cf_max =3D atoi(p[1]); - cf_per =3D atoi(p[2]); + cf_max =3D atoi_warn(p[1], msglevel); + cf_per =3D atoi_warn(p[2], msglevel); if (cf_max < 0 || cf_per < 0) { msg(msglevel, "--connect-freq parms must be > 0"); @@ -7634,7 +7685,7 @@ int max_clients; VERIFY_PERMISSION(OPT_P_GENERAL); - max_clients =3D atoi(p[1]); + max_clients =3D atoi_warn(p[1], msglevel); if (max_clients < 0) { msg(msglevel, "--max-clients must be at least 1"); @@ -7650,7 +7701,7 @@ else if (streq(p[0], "max-routes-per-client") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_INHERIT); - options->max_routes_per_client =3D max_int(atoi(p[1]), 1); + options->max_routes_per_client =3D max_int(positive_atoi(p[1], msg= level), 1); } else if (streq(p[0], "client-cert-not-required") && !p[1]) { @@ -7734,14 +7785,14 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); options->auth_token_generate =3D true; - options->auth_token_lifetime =3D p[1] ? positive_atoi(p[1]) : 0; + options->auth_token_lifetime =3D p[1] ? positive_atoi(p[1], msglev= el) : 0; for (int i =3D 2; i < MAX_PARMS && p[i] !=3D NULL; i++) { /* the second parameter can be the renewal time */ - if (i =3D=3D 2 && positive_atoi(p[i])) + if (i =3D=3D 2 && valid_integer(p[i], true)) { - options->auth_token_renewal =3D positive_atoi(p[i]); + options->auth_token_renewal =3D positive_atoi(p[i], msglev= el); } else if (streq(p[i], "external-auth")) { @@ -7821,7 +7872,7 @@ int n_bcast_buf; VERIFY_PERMISSION(OPT_P_GENERAL); - n_bcast_buf =3D atoi(p[1]); + n_bcast_buf =3D atoi_warn(p[1], msglevel); if (n_bcast_buf < 1) { msg(msglevel, "--bcast-buffers parameter must be > 0"); @@ -7833,7 +7884,7 @@ int tcp_queue_limit; VERIFY_PERMISSION(OPT_P_GENERAL); - tcp_queue_limit =3D atoi(p[1]); + tcp_queue_limit =3D atoi_warn(p[1], msglevel); if (tcp_queue_limit < 1) { msg(msglevel, "--tcp-queue-limit parameter must be > 0"); @@ -7964,10 +8015,10 @@ int ageing_time, check_interval; VERIFY_PERMISSION(OPT_P_GENERAL); - ageing_time =3D atoi(p[1]); + ageing_time =3D atoi_warn(p[1], msglevel); if (p[2]) { - check_interval =3D atoi(p[2]); + check_interval =3D atoi_warn(p[2], msglevel); } else { @@ -7996,7 +8047,7 @@ else if (streq(p[0], "push-continuation") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_PULL_MODE); - options->push_continuation =3D atoi(p[1]); + options->push_continuation =3D atoi_warn(p[1], msglevel); } else if (streq(p[0], "auth-user-pass") && !p[2]) { @@ -8021,7 +8072,7 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); options->sc_info.challenge_text =3D p[1]; - if (atoi(p[2])) + if (atoi_warn(p[2], msglevel)) { options->sc_info.flags |=3D SC_ECHO; } @@ -8117,7 +8168,7 @@ { if (!streq(p[2], "default")) { - int offset =3D atoi(p[2]); + int offset =3D atoi_warn(p[2], msglevel); if (!(offset > -256 && offset < 256)) { @@ -8133,7 +8184,7 @@ { const int min_lease =3D 30; int lease_time; - lease_time =3D atoi(p[3]); + lease_time =3D atoi_warn(p[3], msglevel); if (lease_time < min_lease) { msg(msglevel, "--ip-win32 dynamic [offset] [lease-= time]: lease time parameter (%d) must be at least %d seconds", lease_time, = min_lease); @@ -8257,7 +8308,7 @@ else if (streq(p[1], "NBT") && p[2] && !p[3]) { int t; - t =3D atoi(p[2]); + t =3D atoi_warn(p[2], msglevel); if (!(t =3D=3D 1 || t =3D=3D 2 || t =3D=3D 4 || t =3D=3D 8)) { msg(msglevel, "--dhcp-option NBT: parameter (%d) must be 1= , 2, 4, or 8", t); @@ -8315,7 +8366,7 @@ #if defined(TARGET_ANDROID) else if (streq(p[1], "PROXY_HTTP") && p[3] && !p[4]) { - o->http_proxy_port =3D atoi(p[3]); + o->http_proxy_port =3D positiove_atoi(p[3], msglevel); o->http_proxy =3D p[2]; } #endif @@ -8349,7 +8400,7 @@ { int s; VERIFY_PERMISSION(OPT_P_DHCPDNS); - s =3D atoi(p[1]); + s =3D atoi_warn(p[1], msglevel); if (s < 0 || s >=3D 256) { msg(msglevel, "--tap-sleep parameter must be between 0 and 255= "); @@ -8432,7 +8483,7 @@ options->exit_event_name =3D p[1]; if (p[2]) { - options->exit_event_initial_state =3D (atoi(p[2]) !=3D 0); + options->exit_event_initial_state =3D (atoi_warn(p[2], msgleve= l) !=3D 0); } } else if (streq(p[0], "allow-nonadmin") && !p[2]) @@ -8799,7 +8850,7 @@ { int replay_window; - replay_window =3D atoi(p[1]); + replay_window =3D atoi_warn(p[1], msglevel); if (!(MIN_SEQ_BACKTRACK <=3D replay_window && replay_window <= =3D MAX_SEQ_BACKTRACK)) { msg(msglevel, "replay-window window size parameter (%d) mu= st be between %d and %d", @@ -8814,7 +8865,7 @@ { int replay_time; - replay_time =3D atoi(p[2]); + replay_time =3D atoi_warn(p[2], msglevel); if (!(MIN_TIME_BACKTRACK <=3D replay_time && replay_time <= =3D MAX_TIME_BACKTRACK)) { msg(msglevel, "replay-window time window parameter (%d= ) must be between %d and %d", @@ -9256,7 +9307,7 @@ else if (streq(p[0], "tls-timeout") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TLS_PARMS); - options->tls_timeout =3D positive_atoi(p[1]); + options->tls_timeout =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "reneg-bytes") && p[1] && !p[2]) { @@ -9285,21 +9336,21 @@ else if (streq(p[0], "reneg-sec") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_TLS_PARMS); - options->renegotiate_seconds =3D positive_atoi(p[1]); + options->renegotiate_seconds =3D positive_atoi(p[1], msglevel); if (p[2]) { - options->renegotiate_seconds_min =3D positive_atoi(p[2]); + options->renegotiate_seconds_min =3D positive_atoi(p[2], msgle= vel); } } else if (streq(p[0], "hand-window") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TLS_PARMS); - options->handshake_window =3D positive_atoi(p[1]); + options->handshake_window =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "tran-window") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_TLS_PARMS); - options->transition_window =3D positive_atoi(p[1]); + options->transition_window =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "tls-auth") && p[1] && !p[3]) { @@ -9436,7 +9487,7 @@ else if (streq(p[0], "show-pkcs11-ids") && !p[3]) { char *provider =3D p[1]; - bool cert_private =3D (p[2] =3D=3D NULL ? false : ( atoi(p[2]) != =3D 0 )); + bool cert_private =3D (p[2] =3D=3D NULL ? false : (atoi_warn(p[2],= msglevel) !=3D 0 )); #ifdef DEFAULT_PKCS11_MODULE if (!provider) @@ -9488,7 +9539,7 @@ for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - options->pkcs11_protected_authentication[j-1] =3D atoi(p[j]) != =3D 0 ? 1 : 0; + options->pkcs11_protected_authentication[j-1] =3D atoi_warn(p[= j], msglevel) !=3D 0 ? 1 : 0; } } else if (streq(p[0], "pkcs11-private-mode") && p[1]) @@ -9510,13 +9561,13 @@ for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - options->pkcs11_cert_private[j-1] =3D atoi(p[j]) !=3D 0 ? 1 : = 0; + options->pkcs11_cert_private[j-1] =3D atoi_warn(p[j], msglevel= ) !=3D 0 ? 1 : 0; } } else if (streq(p[0], "pkcs11-pin-cache") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL); - options->pkcs11_pin_cache_period =3D atoi(p[1]); + options->pkcs11_pin_cache_period =3D atoi_warn(p[1], msglevel); } else if (streq(p[0], "pkcs11-id") && p[1] && !p[2]) { @@ -9545,12 +9596,12 @@ { VERIFY_PERMISSION(OPT_P_PEER_ID); options->use_peer_id =3D true; - options->peer_id =3D atoi(p[1]); + options->peer_id =3D atoi_warn(p[1], msglevel); } #ifdef HAVE_EXPORT_KEYING_MATERIAL else if (streq(p[0], "keying-material-exporter") && p[1] && p[2]) { - int ekm_length =3D positive_atoi(p[2]); + int ekm_length =3D positive_atoi(p[2], msglevel); VERIFY_PERMISSION(OPT_P_GENERAL); @@ -9609,7 +9660,7 @@ else if (streq(p[0], "vlan-pvid") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE); - options->vlan_pvid =3D positive_atoi(p[1]); + options->vlan_pvid =3D positive_atoi(p[1], msglevel); if (options->vlan_pvid < OPENVPN_8021Q_MIN_VID || options->vlan_pvid > OPENVPN_8021Q_MAX_VID) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/873?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ie1e2eb54d516b3ae87c5ca56fe8edd77ee2be4de Gerrit-Change-Number: 873 Gerrit-PatchSet: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --uf7qQAjlaBg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

plaisthos uploaded patch set #4 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/873?usp=3Demail">View Chang= e

Print warnings/errors when numerical parameters cannot be parsed
<= br>Using the atoi method is a best effort method that parses as much of the=
input string as possible as integer and ignores the rest or return 0if the string cannot be parsed. This is lead to unexpected results.
Change the behaviour by printing a warning in these cases instead. Whenparsing a configuration, these warnings will error out since the msglevel<= br>is M_USAGE in this case. Example:

./src/openvpn/openvpn --res= olv-retry 198jj
Options error: Cannot parse argument '198jj'= as non-negative integer

Reported-By: Anqi Chen <chen.anqi3@...2825...= 55...>
Reported-By: Cristina Nita-Rotaru <c.nitarotaru@...2855...&= gt;
Change-Id: Ie1e2eb54d516b3ae87c5ca56fe8edd77ee2be4de
Signed-off-b= y: Arne Schwabe <arne@...1227...>
---
M src/openvpn/options.c1 file changed, 129 insertions(+), 78 deletions(-)

git pull ssh=
://gerrit.openvpn.net:29418/openvpn refs/changes/73/873/4
diff --=
git a/src/openvpn/options.c b/src/openvpn/options.c
index b= d5c056..69b0148 100644
--- a/src/openvpn/options.c+++ b/src/openvpn/options.c
@@ -5014,11 +5014,62 @@=
}
#endif

-static int
-positive_atoi(const char *str)
+/** Checks if the string is a valid= integer by checking if it can be
+ * converted to an integer */
+static bool
+valid_integer(const char *str, bool positive)
{
- const int i= =3D atoi(str);
- re= turn i < 0 ? 0 : i;
= + long long i =3D strtoll(str, &endptr, 10);
+
+ if (i < INT_MIN || (positive && i < 0) || = *endptr !=3D '\0' || i > INT_MAX)
+ {
+ return false
+ }
+ = else
+ {<= br>+ return true;=
+ }
+}
+
+
+/**
+ * Converts a str to a positive numbe= r if the string represents a postive
+ * integer number. Otherwise print a warning with msglevel= and return 0
+ */

+static int
<= span style=3D"color: hsl(120, 100%, 40%);">+positive_atoi(const char *str, = int msglevel)
+{
+ char *endptr;=
+ long long i =3D strtol= l(str, &endptr, 10);
+
+ if (i <= 0 || *endptr !=3D '\0' || i > INT_MAX)
+ {
+ msg(msglevel, "Cannot parse argument '%s&= #39; as non-negative integer",
+ str);
+ i =3D 0;
+ }
+
+ return (int) i;
+}
+
+/**
+= * Converts a str to an integer if the string can be represented as an
+ * integer number. Other= wise print a warning with msglevel and return 0
+ */
+static int
+{
+ char *endptr;
+ long long i =3D strtoll(str, &endptr, 10);
+
+ if (i < INT_MIN || *endptr !=3D '\0' || i &g= t; INT_MAX)
+ {
+ msg(msglevel, = "Cannot parse argument '%s' as integer", str);
= + i =3D 0;
+ }

+
+ return (int) i;
}
#ifdef _WIN32 /* This function is only used when compiling on Wind= ows */
@@ -6043,7 +6094,7 @@
int c= ache;

VERIFY_PERMISSION(OPT_P_GE= NERAL);
- cache = =3D atoi(p[1]);
+ = cache =3D atoi_warn(p[1], msglevel);
if (cache= < 1)
{
msg(msglev= el, "--management-log-cache parameter is out of range");@@ -6355,7 +6406,7 @@
}
= else
{
- options->resolve_retry_seconds =3D positive= _atoi(p[1]);
+ = options->resolve_retry_seconds =3D positive_atoi(p[1], msglevel);
}
}
else = if ((streq(p[0], "preresolve") || streq(p[0], "ip-remote-hin= t")) && !p[2])
@@ -6372,7 +6423,7 @@ else if (streq(p[0], "connect-retry") && p[1]= && !p[3])
{
VERIFY_P= ERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
- options->ce.connect_retry_seconds =3D posit= ive_atoi(p[1]);
+ = options->ce.connect_retry_seconds =3D positive_atoi(p[1], msglevel);=
/*
* Limit the base val= ue of retry wait interval to 16 bits to avoid
* o= verflow when scaled up for exponential backoff
@@ -6387,19 = +6438,19 @@
if (p[2])
{
options->ce.connect_retry_seconds_max =3D
- max_int(= positive_atoi(p[2]), options->ce.connect_retry_seconds);
+ max_int(positive_at= oi(p[2], msglevel), options->ce.connect_retry_seconds);

= }
}
else if ((streq(p[0]= , "connect-timeout") || streq(p[0], "server-poll-timeout&quo= t;))
&& p[1] && !p[2])=
{
VERIFY_PERMISSION(OPT_P_GENERAL|O= PT_P_CONNECTION);
- = options->ce.connect_timeout =3D positive_atoi(p[1]);
+ options->ce.connect_time= out =3D positive_atoi(p[1], msglevel);

}
else if (streq(p[0], "connect-retry-max") && p[1]= && !p[2])

{
VERIFY_P= ERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
- options->connect_retry_max =3D positive_ato= i(p[1]);
+ opt= ions->connect_retry_max =3D positive_atoi(p[1], msglevel);
}

else if (streq(p[0], "ipchange") &= amp;& p[1])
{
@@ -6422,7 +6473,7 @= @
else if (streq(p[0], "gremlin") &&= p[1] && !p[2])
{
VER= IFY_PERMISSION(OPT_P_GENERAL);
- options->gremlin =3D positive_atoi(p[1]);
+ options->gremlin =3D p= ositive_atoi(p[1], msglevel);

}
#endi= f
else if (streq(p[0], "chroot") && = p[1] && !p[2])
@@ -6554,7 +6605,7 @@
else if (streq(p[0], "verb") && p[1] && !p= [2])

{
VERIFY_PERMISSION(OPT_= P_MESSAGES);
- o= ptions->verbosity =3D positive_atoi(p[1]);
+ options->verbosity =3D positive_atoi(p= [1], msglevel);
if (options->verbosity >=3D = (D_TLS_DEBUG_MED & M_DEBUG_LEVEL))
{ /* We pass this flag to the SSL library to avoid=
@@ -6573,7 +6624,7 @@
else if (streq(p[0], &= quot;mute") && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_MESSAGES);
- options->mute =3D positive_= atoi(p[1]);
+ = options->mute =3D positive_atoi(p[1], msglevel);
}<= /span>
else if (streq(p[0], "errors-to-stderr") &am= p;& !p[1])
{
@@ -6586,7 +6637,7 @@=
options->status_file =3D p[1];
if (p[2])

{
- options->status_file_update_freq = =3D positive_atoi(p[2]);
+ options->status_file_update_freq =3D positive_atoi(p[2]= , msglevel);
}
}
else if (streq(p[0], "status-version") && p[1] &= amp;& !p[2])

@@ -6594,7 +6645,7 @@
= int version;

VERIFY_PERMISS= ION(OPT_P_GENERAL);
- = version =3D atoi(p[1]);
+ version =3D atoi_warn(p[1], msglevel);
= if (version < 1 || version > 3)
{

msg(msglevel, "--status-version must be 1 to= 3");
@@ -6622,17 +6673,17 @@
els= e if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu"= )) && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
- options->ce.link_mtu =3D posi= tive_atoi(p[1]);
+ = options->ce.link_mtu =3D positive_atoi(p[1], msglevel);
<= span> options->ce.link_mtu_defined =3D true;
= }
else if (streq(p[0], "tun-mtu") &&am= p; p[1] && !p[3])
{
V= ERIFY_PERMISSION(OPT_P_PUSH_MTU|OPT_P_CONNECTION);
- options->ce.tun_mtu =3D positive_at= oi(p[1]);
+ op= tions->ce.tun_mtu =3D positive_atoi(p[1], msglevel);
= options->ce.tun_mtu_defined =3D true;
if = (p[2])
{
- options->ce.occ_mtu =3D positive_atoi(p[2]);
+ options->= ;ce.occ_mtu =3D positive_atoi(p[2], msglevel);
}
else
{
@@ = -6642,7 +6693,7 @@
else if (streq(p[0], "tun-mtu-= max") && p[1] && !p[3])
{<= br> VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
= - int max_mtu =3D positive= _atoi(p[1]);
+ = int max_mtu =3D positive_atoi(p[1], msglevel);
if= (max_mtu < 68 || max_mtu > 65536)
{<= br> msg(msglevel, "--tun-mtu-max value '%s' = is invalid", p[1]);
@@ -6655,13 +6706,13 @@
= else if (streq(p[0], "tun-mtu-extra") && p[1] = && !p[2])
{
VERIFY_PE= RMISSION(OPT_P_MTU|OPT_P_CONNECTION);
- options->ce.tun_mtu_extra =3D positive_atoi(p[1]= );
+ options-&= gt;ce.tun_mtu_extra =3D positive_atoi(p[1], msglevel);
= options->ce.tun_mtu_extra_defined =3D true;
}<= /span>
else if (streq(p[0], "max-packet-size") &= ;& p[1] && !p[2])
{
= VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
- int maxmtu =3D positive_atoi(p[1]);
+ int maxmtu =3D = positive_atoi(p[1], msglevel);
options->ce.tls_= mtu =3D constrain_int(maxmtu, TLS_CHANNEL_MTU_MIN, TLS_CHANNEL_BUF_SIZE);

if (maxmtu < TLS_CHANNEL_MTU_M= IN || maxmtu > TLS_CHANNEL_BUF_SIZE)
@@ -6687,7 +6738,7 = @@
else if (streq(p[0], "fragment") &&am= p; p[1] && !p[3])
{
V= ERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
- options->ce.fragment =3D positive_atoi(p= [1]);
+ option= s->ce.fragment =3D positive_atoi(p[1], msglevel);

if (options->ce.fragment < 68)
= {
@@ -6718,23 +6769,23 @@
else= if (streq(p[0], "nice") && p[1] && !p[2])=
{
VERIFY_PERMISSION(OPT_P_NICE);
- options->nice= =3D atoi(p[1]);
+ = options->nice =3D atoi_warn(p[1], msglevel);
}=
else if (streq(p[0], "rcvbuf") && p= [1] && !p[2])
{
VERIF= Y_PERMISSION(OPT_P_SOCKBUF);
- options->rcvbuf =3D positive_atoi(p[1]);
+ options->rcvbuf =3D posit= ive_atoi(p[1], msglevel);
}
else = if (streq(p[0], "sndbuf") && p[1] && !p[2])

{
VERIFY_PERMISSION(OPT_P_SOCKBUF)= ;
- options->= sndbuf =3D positive_atoi(p[1]);
+ options->sndbuf =3D positive_atoi(p[1], msglevel);
}
else if (streq(p[0], "mark&= quot;) && p[1] && !p[2])
{
<= span> #if defined(TARGET_LINUX) && HAVE_DECL_SO_MARK

VERIFY_PERMISSION(OPT_P_GENERAL);
- options->mark =3D atoi(p[1]);
<= span style=3D"color: hsl(120, 100%, 40%);">+ options->mark =3D at= oi_warn(p[1], msglevel);
#endif
}
else if (streq(p[0], "socket-flags"))@@ -6764,7 +6815,7 @@
{
= VERIFY_PERMISSION(OPT_P_GENERAL);
#ifdef TARGET_LINUX
- options->tunt= ap_options.txqueuelen =3D positive_atoi(p[1]);
+ options->tuntap_options.txqueuelen = =3D positive_atoi(p[1], msglevel);
#else
= msg(msglevel, "--txqueuelen not supported on this OS");
goto err;
@@ -6775,7 +6826,7 @@
int shaper;

= VERIFY_PERMISSION(OPT_P_SHAPER);
- shaper =3D atoi(p[1]);
+ shaper =3D atoi_warn(p[1], msglevel);
if (shaper < SHAPER_MIN || shaper > SHAPER_MAX)
{
msg(msglevel, "= Bad shaper value, must be between %d and %d",
@@ -6823= ,7 +6874,7 @@
else if (streq(p[0], "inactive"= ;) && p[1] && !p[3])
{
VERIFY_PERMISSION(OPT_P_TIMER);

- options->inactivity_timeout =3D positive_ato= i(p[1]);
+ opt= ions->inactivity_timeout =3D positive_atoi(p[1], msglevel);
if (p[2])

{
= int64_t val =3D atoll(p[2]);
@@ -6841,7 +6892,7 @@

else if (streq(p[0], "session-timeout") &&am= p; p[1] && !p[2])
{
V= ERIFY_PERMISSION(OPT_P_TIMER);
- options->session_timeout =3D positive_atoi(p[1]);
+ options->sessi= on_timeout =3D positive_atoi(p[1], msglevel);
}=
else if (streq(p[0], "proto") && p[1] &= ;& !p[2])
{
@@ -7008,24 +7059,24 @= @
else if (streq(p[0], "keepalive") &&am= p; p[1] && p[2] && !p[3])
{
= VERIFY_PERMISSION(OPT_P_GENERAL);
- options->keepalive_ping =3D atoi(p[1]= );
- options->= ;keepalive_timeout =3D atoi(p[2]);
+ options->keepalive_ping =3D atoi_warn(p[1], msgle= vel);
+ option= s->keepalive_timeout =3D atoi_warn(p[2], msglevel);
= }
else if (streq(p[0], "ping") && p= [1] && !p[2])
{
VERIF= Y_PERMISSION(OPT_P_TIMER);
- options->ping_send_timeout =3D positive_atoi(p[1]);<= br>+ options->ping_se= nd_timeout =3D positive_atoi(p[1], msglevel);
}=
else if (streq(p[0], "ping-exit") && p[1] = && !p[2])
{
VERIFY_PE= RMISSION(OPT_P_TIMER);
= - options->ping_rec_timeout =3D positive_atoi(p[1]);
+ options->ping_rec_tim= eout =3D positive_atoi(p[1], msglevel);

options-&g= t;ping_rec_timeout_action =3D PING_EXIT;
}
<= span> else if (streq(p[0], "ping-restart") && p[1] &a= mp;& !p[2])
{
VERIFY_PERM= ISSION(OPT_P_TIMER);
- = options->ping_rec_timeout =3D positive_atoi(p[1]);
+ options->ping_rec_timeo= ut =3D positive_atoi(p[1], msglevel);
options->= ping_rec_timeout_action =3D PING_RESTART;
}
= else if (streq(p[0], "ping-timer-rem") && !p[1= ])
@@ -7038,7 +7089,7 @@
VERIFY_PE= RMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_EXPLICIT_NOTIFY);
<= span> if (p[1])
{
- options->ce.explicit_exit_notif= ication =3D positive_atoi(p[1]);
+ options->ce.explicit_exit_notification =3D posi= tive_atoi(p[1], msglevel);
}
= else
{
@@ -7158,7 +7209,7 @@
else if (streq(p[0], "route-metric") &&am= p; p[1] && !p[2])
{
V= ERIFY_PERMISSION(OPT_P_ROUTE);
- options->route_default_metric =3D positive_atoi(p[1]);<= /span>
+ options->= route_default_metric =3D positive_atoi(p[1], msglevel);
= }
else if (streq(p[0], "route-delay") &= ;& !p[3])
{
@@ -7166,10 +7217,10 @= @
options->route_delay_defined =3D true;=
if (p[1])
{
- options->route_delay =3D p= ositive_atoi(p[1]);
+= options->route_delay =3D positive_atoi(p[1], msglevel);

if (p[2])
{- options->rou= te_delay_window =3D positive_atoi(p[2]);
+ options->route_delay_window =3D pos= itive_atoi(p[2], msglevel);
}
= }
else
@@ -7334,7 +7385,7= @@
}
else if (streq(p[1]= , "SERVER_POLL_TIMEOUT") && p[2])
= {
- option= s->ce.connect_timeout =3D positive_atoi(p[2]);
+ options->ce.connect_timeout = =3D positive_atoi(p[2], msglevel);
}
else
{
@@ -7366,14 +74= 17,14 @@
else if (streq(p[0], "script-security&qu= ot;) && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_GENERAL);
- script_security_set(atoi(p[1]));
= + script_security_set(at= oi_warn(p[1], msglevel));
}
else = if (streq(p[0], "mssfix") && !p[3])
= {
VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION= );
if (p[1])
{
= - int mssfix =3D posit= ive_atoi(p[1]);
+ = int mssfix =3D positive_atoi(p[1], msglevel);
= /* can be 0, but otherwise it needs to be high enough so we can

* substract room for headers. */
if (mssfix !=3D 0
@@ -7556,7 +7607,7 @@

options->ifconfig_pool_persist_filename =3D p[1];
if (p[2])
{
- options->ifconfig_pool= _persist_refresh_freq =3D positive_atoi(p[2]);

+ options->ifconfig_pool_persist_re= fresh_freq =3D positive_atoi(p[2], msglevel);
}
}
else if (streq(p[0], "ifconf= ig-ipv6-pool") && p[1] && !p[2])
@@ -7= 588,8 +7639,8 @@
int real, virtual;

VERIFY_PERMISSION(OPT_P_GENERAL);
- real =3D atoi(p[1]);
- virtual =3D atoi(p[= 2]);
+ real = =3D atoi_warn(p[1], msglevel);
+ virtual =3D atoi_warn(p[1], msglevel);
= if (real < 1 || virtual < 1)
{
msg(msglevel, "--hash-size sizes must be >= =3D 1 (preferably a power of 2)");
@@ -7603,8 +7654,8 = @@
int cf_max, cf_per;
VERIFY_PERMISSION(OPT_P_GENERAL);
- cf_max =3D atoi(p[1]);
- cf_per =3D atoi(p[2]);<= br>+ cf_max =3D atoi_war= n(p[1], msglevel);
+ = cf_per =3D atoi_warn(p[2], msglevel);
if (c= f_max < 0 || cf_per < 0)
{
= msg(msglevel, "--connect-freq parms must be > 0");=
@@ -7634,7 +7685,7 @@
int max_cli= ents;

VERIFY_PERMISSION(OPT_P_GE= NERAL);
- max_cl= ients =3D atoi(p[1]);
+ max_clients =3D atoi_warn(p[1], msglevel);
= if (max_clients < 0)
{
= msg(msglevel, "--max-clients must be at least 1");=
@@ -7650,7 +7701,7 @@
else if (streq(p[0], &= quot;max-routes-per-client") && p[1] && !p[2])<= br> {
VERIFY_PERMISSION(OPT_P_INHERIT);<= /span>
- options->ma= x_routes_per_client =3D max_int(atoi(p[1]), 1);
+ options->max_routes_per_client =3D m= ax_int(positive_atoi(p[1], msglevel), 1);
}
= else if (streq(p[0], "client-cert-not-required") &= & !p[1])
{
@@ -7734,14 +7785,14 @@=
{
VERIFY_PERMISSION(OPT_P_GE= NERAL);
options->auth_token_generate =3D true;<= /span>
- options->au= th_token_lifetime =3D p[1] ? positive_atoi(p[1]) : 0;
+ options->auth_token_lifetime = =3D p[1] ? positive_atoi(p[1], msglevel) : 0;

<= span> for (int i =3D 2; i < MAX_PARMS && p[i] !=3D NULL;= i++)

{
/* the second= parameter can be the renewal time */
- if (i =3D=3D 2 && positive_atoi(p[i]))<= /span>
+ if (i = =3D=3D 2 && valid_integer(p[i], true))
= {
- opt= ions->auth_token_renewal =3D positive_atoi(p[i]);
+ options->auth_token_re= newal =3D positive_atoi(p[i], msglevel);
}

else if (streq(p[i], "external-auth"))<= /span>
{
@@ -7821,7 +7872,7 @@=
int n_bcast_buf;

= VERIFY_PERMISSION(OPT_P_GENERAL);
- n_bcast_buf =3D atoi(p[1]);
+ n_bcast_buf =3D atoi_warn(p[1], m= sglevel);
if (n_bcast_buf < 1)
= {
msg(msglevel, "--bcast-buffers= parameter must be > 0");
@@ -7833,7 +7884,7 @@
int tcp_queue_limit;

VERIFY_PERMISSION(OPT_P_GENERAL);

- tcp_queue_limit =3D atoi(p[1]);
+ tcp_queue_limit =3D atoi= _warn(p[1], msglevel);

if (tcp_queue_limit < 1)=
{
msg(msglevel, &quo= t;--tcp-queue-limit parameter must be > 0");
@@ -79= 64,10 +8015,10 @@
int ageing_time, check_interval;=

VERIFY_PERMISSION(OPT_P_GENERAL= );
- ageing_time= =3D atoi(p[1]);
+ = ageing_time =3D atoi_warn(p[1], msglevel);
if= (p[2])
{
- check_interval =3D atoi(p[2]);
+ check_interval =3D atoi_war= n(p[2], msglevel);
}
else=
{
@@ -7996,7 +8047,7 @@ else if (streq(p[0], "push-continuation") && = p[1] && !p[2])
{
VERI= FY_PERMISSION(OPT_P_PULL_MODE);
- options->push_continuation =3D atoi(p[1]);
<= span style=3D"color: hsl(120, 100%, 40%);">+ options->push_contin= uation =3D atoi_warn(p[1], msglevel);
}
else if (streq(p[0], "auth-user-pass") && !p[2])
{
@@ -8021,7 +8072,7 @@
{
VERIFY_PERMISSION(OPT_P_GENERAL); options->sc_info.challenge_text =3D p[1];
- if (atoi(p[2]))
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (atoi_warn(p[2], msg= level))
{
options->= ;sc_info.flags |=3D SC_ECHO;
}
@@ = -8117,7 +8168,7 @@
{
= if (!streq(p[2], "default"))
= {
- = int offset =3D atoi(p[2]);
+ int offset =3D atoi_warn(p[2], msglevel);

if (!(offset > -25= 6 && offset < 256))
{

@@ -8133,7 +8184,7 @@
{<= br> const int min_lease =3D 30;
= int lease_time;
- lease_time =3D atoi(p[3]);
+ lease_time =3D= atoi_warn(p[3], msglevel);
if (lease_= time < min_lease)
{
msg(msglevel, "--ip-win32 dynamic [offset] [= lease-time]: lease time parameter (%d) must be at least %d seconds", l= ease_time, min_lease);
@@ -8257,7 +8308,7 @@
else if (streq(p[1], "NBT") && p[2] &&= !p[3])
{
int t;

- t =3D atoi(p[2= ]);
+ t = =3D atoi_warn(p[2], msglevel);
if (!(t =3D=3D = 1 || t =3D=3D 2 || t =3D=3D 4 || t =3D=3D 8))
= {
msg(msglevel, "--dhcp-option NBT: p= arameter (%d) must be 1, 2, 4, or 8", t);
@@ -8315,7 += 8366,7 @@
#if defined(TARGET_ANDROID)
= else if (streq(p[1], "PROXY_HTTP") && p[3] &&= ; !p[4])
{
- o->http_proxy_port =3D atoi(p[3]);
<= span style=3D"color: hsl(120, 100%, 40%);">+ o->http_proxy_po= rt =3D positiove_atoi(p[3], msglevel);
o->h= ttp_proxy =3D p[2];
}
#endif

@@ -8349,7 +8400,7 @@
{
= int s;
VERIFY_PERMISSION(OPT_P_DHCPDNS);
- s =3D atoi(p[1])= ;
+ s =3D atoi= _warn(p[1], msglevel);
if (s < 0 || s >=3D 2= 56)
{
msg(msglevel, &= quot;--tap-sleep parameter must be between 0 and 255");
@@ -8432,7 +8483,7 @@

options->exit_event_nam= e =3D p[1];
if (p[2])
{
- options->= ;exit_event_initial_state =3D (atoi(p[2]) !=3D 0);
+ options->exit_event_initial_s= tate =3D (atoi_warn(p[2], msglevel) !=3D 0);
}
}
else if (streq(p[0], "allow-n= onadmin") && !p[2])
@@ -8799,7 +8850,7 @@

{
int replay_window;

- = replay_window =3D atoi(p[1]);
+ replay_window =3D atoi_warn(p[1], msglevel);
if (!(MIN_SEQ_BACKTRACK <=3D replay_window &= ;& replay_window <=3D MAX_SEQ_BACKTRACK))
= {
msg(msglevel, "replay-window win= dow size parameter (%d) must be between %d and %d",
@@= -8814,7 +8865,7 @@
{
= int replay_time;

- replay_time =3D atoi(p[2]);+ replay_time = =3D atoi_warn(p[2], msglevel);
if (!(MIN_T= IME_BACKTRACK <=3D replay_time && replay_time <=3D MAX_TIME_B= ACKTRACK))
{
= msg(msglevel, "replay-window time window parameter (%d) must b= e between %d and %d",
@@ -9256,7 +9307,7 @@
= else if (streq(p[0], "tls-timeout") && p[1] &a= mp;& !p[2])
{
VERIFY_PERM= ISSION(OPT_P_TLS_PARMS);
+ options->tls_timeout =3D= positive_atoi(p[1], msglevel);
}
= else if (streq(p[0], "reneg-bytes") && p[1] && != p[2])
{
@@ -9285,21 +9336,21 @@=
else if (streq(p[0], "reneg-sec") && p[1] = && !p[3])
{
VERIFY_PE= RMISSION(OPT_P_TLS_PARMS);
- options->renegotiate_seconds =3D positive_atoi(p[1]);
+ options->reneg= otiate_seconds =3D positive_atoi(p[1], msglevel);
= if (p[2])
{
- options->renegotiate_seconds_min =3D positive= _atoi(p[2]);
+ = options->renegotiate_seconds_min =3D positive_atoi(p[2], msglevel);=
}
}
els= e if (streq(p[0], "hand-window") && p[1] && !p[2]= )
{
VERIFY_PERMISSION(OPT_P_T= LS_PARMS);
- opt= ions->handshake_window =3D positive_atoi(p[1]);
+ options->handshake_window =3D pos= itive_atoi(p[1], msglevel);
}
els= e if (streq(p[0], "tran-window") && p[1] && !p[2]= )
{
VERIFY_PERMISSION(OPT_P_T= LS_PARMS);
- opt= ions->transition_window =3D positive_atoi(p[1]);
+ options->transition_window =3D= positive_atoi(p[1], msglevel);
}
= else if (streq(p[0], "tls-auth") && p[1] && !p[3= ])
{
@@ -9436,7 +9487,7 @@
<= span> else if (streq(p[0], "show-pkcs11-ids") && !p[3= ])

{
char *provider =3D p[1]= ;
- bool cert_pr= ivate =3D (p[2] =3D=3D NULL ? false : ( atoi(p[2]) !=3D 0 ));
+ bool cert_private =3D (p[= 2] =3D=3D NULL ? false : (atoi_warn(p[2], msglevel) !=3D 0 ));


#ifdef DEFAULT_PKCS11_MODULE
= if (!provider)
@@ -9488,7 +9539,7 @@

for (j =3D 1; j < MAX_PARMS && p[j] !=3D = NULL; ++j)
{
- options->pkcs11_protected_authentication[j-1= ] =3D atoi(p[j]) !=3D 0 ? 1 : 0;
+ options->pkcs11_protected_authentication[j-1] = =3D atoi_warn(p[j], msglevel) !=3D 0 ? 1 : 0;
}
}
else if (streq(p[0], "pkcs11= -private-mode") && p[1])
@@ -9510,13 +9561,13 = @@

for (j =3D 1; j < MAX_PARM= S && p[j] !=3D NULL; ++j)
{
- options->pkcs11_cert_= private[j-1] =3D atoi(p[j]) !=3D 0 ? 1 : 0;

+ options->pkcs11_cert_private[j-1] = =3D atoi_warn(p[j], msglevel) !=3D 0 ? 1 : 0;
}
}
else if (streq(p[0], "pkcs11= -pin-cache") && p[1] && !p[2])
{<= /span>
VERIFY_PERMISSION(OPT_P_GENERAL);
- options->pkcs11_pin_cache_p= eriod =3D atoi(p[1]);
+ options->pkcs11_pin_cache_period =3D atoi_warn(p[1], msglevel)= ;
}
else if (streq(p[0], "pk= cs11-id") && p[1] && !p[2])
{
@@ -9545,12 +9596,12 @@
{
VERIFY_PERMISSION(OPT_P_PEER_ID);

option= s->use_peer_id =3D true;
- options->peer_id =3D atoi(p[1]);
+ options->peer_id =3D atoi_warn(p[1= ], msglevel);
}
#ifdef HAVE_EXPORT_KE= YING_MATERIAL
else if (streq(p[0], "keying-materi= al-exporter") && p[1] && p[2])
{<= /span>
- int ekm_length= =3D positive_atoi(p[2]);
+ int ekm_length =3D positive_atoi(p[2], msglevel);
<= span>

VERIFY_PERMISSION(OPT_P_GENERAL);
@@ -9609,7 +9660,7 @@
else if= (streq(p[0], "vlan-pvid") && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_GENERAL= |OPT_P_INSTANCE);
- = options->vlan_pvid =3D positive_atoi(p[1]);
+ options->vlan_pvid =3D positive_a= toi(p[1], msglevel);
if (options->vlan_pvid <= ; OPENVPN_8021Q_MIN_VID
|| options->vlan_pv= id > OPENVPN_8021Q_MAX_VID)
{
<= /span>

To view, visit change 873. To unsubscribe, or for help writin= g mail filters, visit settin= gs.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie1e2eb54d516b3ae87c5ca56fe8= edd77ee2be4de
Gerrit-Change-Number: 873
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--uf7qQAjlaBg=--