From: "cron2 (Code Review)" Date: Fri, 10 Oct 2025 07:33:25 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <5f4397fe3f4a213e9615e0a68fe4013640c74ca7-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="pt8niS8ENTg="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: options: Review use of positive_atoi vs atoi_constrained List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos , MaxF Cc: openvpn-devel --pt8niS8ENTg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#7) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1153?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: options: Review use of positive_atoi vs atoi_constrained ...................................................................... options: Review use of positive_atoi vs atoi_constrained Replace where it is useful. While here also add a missing cast in atoi_constrained. Change-Id: Id440917f433aab1a7db608ba04fa95ba47c2ddde Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1153 Message-Id: <20251009205951.32301-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59244617/ Signed-off-by: Gert Doering --- M src/openvpn/options.c 1 file changed, 21 insertions(+), 31 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1153/7 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index fabcc1e..fec17b4 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -6421,21 +6421,15 @@ else if (streq(p[0], "tun-mtu-max") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); - 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]); - } - else - { - options->ce.tun_mtu_max =3D max_mtu; - } + atoi_constrained(p[1], &options->ce.tun_mtu_max, p[0], TUN_MTU_MAX= _MIN, 65536, msglevel); } 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], msglevel); - options->ce.tun_mtu_extra_defined =3D true; + if (atoi_constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, 65= 536, msglevel)) + { + options->ce.tun_mtu_extra_defined =3D true; + } } else if (streq(p[0], "max-packet-size") && p[1] && !p[2]) { @@ -6467,11 +6461,8 @@ 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], msglevel); - - if (options->ce.fragment < 68) + if (!atoi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_M= AX, msglevel)) { - msg(msglevel, "--fragment needs to be at least 68"); goto err; } @@ -7145,12 +7136,14 @@ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); if (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 && (mssfix < TLS_CHANNEL_MTU_MIN || mssfix >= UINT16_MAX)) + int mssfix; + if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msgl= evel)) { - msg(msglevel, "--mssfix value '%s' is invalid", p[1]); + goto err; + } + if (mssfix !=3D 0 && mssfix < TLS_CHANNEL_MTU_MIN) + { + msg(msglevel, "mssfix needs to be >=3D %d, not %d", TLS_CH= ANNEL_MTU_MIN, mssfix); goto err; } @@ -7403,7 +7396,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(positive_atoi(p[1], msg= level), 1); + atoi_constrained(p[1], &options->max_routes_per_client, p[0], 1, I= NT_MAX, msglevel); } else if (streq(p[0], "client-cert-not-required") && !p[1]) { @@ -9222,8 +9215,6 @@ } else if (streq(p[0], "keying-material-exporter") && p[1] && p[2]) { - int ekm_length =3D positive_atoi(p[2], msglevel); - VERIFY_PERMISSION(OPT_P_GENERAL); if (strncmp(p[1], "EXPORTER", 8)) @@ -9237,14 +9228,14 @@ msg(msglevel, "Keying material exporter label must not be '" EXPORT_KEY_= DATA_LABEL "'."); } - if (ekm_length < 16 || ekm_length > 4095) + + if (!atoi_constrained(p[2], &options->keying_material_exporter_len= gth, + p[0], 16, 4095, msglevel)) { - msg(msglevel, "Invalid keying material exporter length"); goto err; } options->keying_material_exporter_label =3D p[1]; - options->keying_material_exporter_length =3D ekm_length; } else if (streq(p[0], "allow-recursive-routing") && !p[1]) { @@ -9279,15 +9270,14 @@ } else if (streq(p[0], "vlan-pvid") && p[1] && !p[2]) { + int vlan_pvid; VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INSTANCE); - options->vlan_pvid =3D positive_atoi(p[1], msglevel); - if (options->vlan_pvid < OPENVPN_8021Q_MIN_VID - || options->vlan_pvid > OPENVPN_8021Q_MAX_VID) + if (!atoi_constrained(p[1], &vlan_pvid, p[0], + OPENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID= , msglevel)) { - msg(msglevel, "the parameter of --vlan-pvid parameters must be= >=3D %u and <=3D %u", - OPENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID); goto err; } + options->vlan_pvid =3D (uint16_t)vlan_pvid; } else { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1153?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id440917f433aab1a7db608ba04fa95ba47c2ddde Gerrit-Change-Number: 1153 Gerrit-PatchSet: 7 Gerrit-Owner: flichtenheld Gerrit-Reviewer: MaxF Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --pt8niS8ENTg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #7 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

options: Review use of positive_ato=
i vs atoi_constrained

Replace where it is useful.

While here = also add a missing cast in atoi_constrained.

Change-Id: Id440917f433= aab1a7db608ba04fa95ba47c2ddde
Signed-off-by: Frank Lichtenheld <frank= @...2641...>
Acked-by: Gert Doering <gert@...1296...>
Gerrit= URL: https://gerrit.openvpn.net/c/openvpn/+/1153
Message-Id: <202510= 09205951.32301-1-gert@...1296...>
URL: https://sourceforge.net/p/open= vpn/mailman/message/59244617/
Signed-off-by: Gert Doering <gert@...1711...= 96...>
---
M src/openvpn/options.c
1 file changed, 21 insertion= s(+), 31 deletions(-)

git pull ssh://gerrit.open=
vpn.net:29418/openvpn refs/changes/53/1153/7
diff --git a/src/openv=
pn/options.c b/src/openvpn/options.c
index fabcc1e..fec17b4= 100644
--- a/src/openvpn/options.c
+++ b/s= rc/openvpn/options.c
@@ -6421,21 +6421,15 @@
else if (streq(p[0], "tun-mtu-max") && p[1] &&= amp; !p[2])
{
VERIFY_PERMISSI= ON(OPT_P_MTU | OPT_P_CONNECTION);
- int max_mtu =3D positive_atoi(p[1], msglevel);- if (max_mtu < 68 ||= max_mtu > 65536)
- = {
- m= sg(msglevel, "--tun-mtu-max value '%s' is invalid", p[1])= ;
- }
= - else
- {
- options->ce.tun_mtu_max =3D max_mtu;
- }
+ atoi_constrained(p[1], &a= mp;options->ce.tun_mtu_max, p[0], TUN_MTU_MAX_MIN, 65536, msglevel);
}
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], msglevel);
- options->ce.tun_mtu_extra_defined =3D tru= e;
+ if (atoi_= constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, 65536, msglev= el))
+ {
+ options->c= e.tun_mtu_extra_defined =3D true;
+ }
}
else if= (streq(p[0], "max-packet-size") && p[1] && !p[2]= )
{
@@ -6467,11 +6461,8 @@
<= span> else if (streq(p[0], "fragment") && p[1] &&= amp; !p[3])

{
VERIFY_PERMISSI= ON(OPT_P_MTU | OPT_P_CONNECTION);
- options->ce.fragment =3D positive_atoi(p[1], msgleve= l);
-
- if (options->ce.fragment <= ; 68)
+ if (!a= toi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msgl= evel))
{
- msg(msglevel, "--fragment needs to be at least= 68");
goto err;
= }

@@ -7145,12 +7136,14 @@
VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);

<= span> if (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 f= or headers. */
- = if (mssfix !=3D 0 && (mssfix < TLS_CHANNEL_MTU_MIN || mssfi= x > UINT16_MAX))
+= int mssfix;
+ if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MA= X, msglevel))
{
- msg(msglevel, "--mssfix value &= #39;%s' is invalid", p[1]);
+ goto err;
+ }
+ if (mssfix !=3D 0 && mssfix < TLS_C= HANNEL_MTU_MIN)
+ = {
+ = msg(msglevel, "mssfix needs to be >=3D %d, not %d", TLS_= CHANNEL_MTU_MIN, mssfix);
goto err;=
}

@@ -7403,7 +7396= ,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 ma= x_int(positive_atoi(p[1], msglevel), 1);
+ atoi_constrained(p[1], &options->max_ro= utes_per_client, p[0], 1, INT_MAX, msglevel);
}=
else if (streq(p[0], "client-cert-not-required") &= amp;& !p[1])
{
@@ -9222,8 +9215,6 = @@
}
else if (streq(p[0], "k= eying-material-exporter") && p[1] && p[2])
<= span> {
- in= t ekm_length =3D positive_atoi(p[2], msglevel);
-
VERIFY_PERMISSION(OPT_P= _GENERAL);

if (strncmp(p[1], &qu= ot;EXPORTER", 8))
@@ -9237,14 +9228,14 @@
msg(msglevel,
"Keyin= g material exporter label must not be '" EXPORT_KEY_DATA_LABEL &qu= ot;'.");
}
- if (ekm_length < 16 || ekm_length > 40= 95)
+
+ if (!atoi_constrained(p[2],= &options->keying_material_exporter_length,
+ p[0], 16, 4095= , msglevel))
{
- msg(msglevel, "Invalid keying material e= xporter length");
goto err;
}

options->keying= _material_exporter_label =3D p[1];
- options->keying_material_exporter_length =3D ekm_le= ngth;
}
else if (streq(p[0], &quo= t;allow-recursive-routing") && !p[1])
{
@@ -9279,15 +9270,14 @@
}
else if (streq(p[0], "vlan-pvid") && p[1] &&a= mp; !p[2])

{
+ int vlan_pvid;
VERIFY_PERMIS= SION(OPT_P_GENERAL | OPT_P_INSTANCE);
- options->vlan_pvid =3D positive_atoi(p[1], msgle= vel);
- if (opti= ons->vlan_pvid < OPENVPN_8021Q_MIN_VID
- || options->vlan_pvid > OPENVPN_80= 21Q_MAX_VID)
+ = if (!atoi_constrained(p[1], &vlan_pvid, p[0],
+ OPENVPN_8021Q_= MIN_VID, OPENVPN_8021Q_MAX_VID, msglevel))
{

- msg(msglevel, &= quot;the parameter of --vlan-pvid parameters must be >=3D %u and <=3D= %u",
- = OPENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID);
= goto err;
}
+ options->vlan_pvid =3D (uint16_t)vlan_pvi= d;
}
else
{<= /span>

To view, visit change 1153. To unsubscribe,= or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id440917f433aab1a7db608ba04f= a95ba47c2ddde
Gerrit-Change-Number: 1153
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: MaxF <max@...2606...> <= /div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --pt8niS8ENTg=--