From: "flichtenheld (Code Review)" Date: Wed, 24 Sep 2025 13:33:58 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="cxA3FpJ1de0="; 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: plaisthos Cc: openvpn-devel --cxA3FpJ1de0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1153?usp=3Demail to look at the new patch set (#5). 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 --- M src/openvpn/options.c M src/openvpn/options_util.c 2 files changed, 22 insertions(+), 40 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1153/5 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index f801743..5192127 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -7019,21 +7019,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]) { @@ -7065,11 +7059,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; } =20 @@ -7743,12 +7734,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; } @@ -8001,7 +7994,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]) { @@ -9808,8 +9801,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)) @@ -9823,14 +9814,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]) { @@ -9865,15 +9856,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 { diff --git a/src/openvpn/options_util.c b/src/openvpn/options_util.c index 8a1c083..2eeecb8 100644 --- a/src/openvpn/options_util.c +++ b/src/openvpn/options_util.c @@ -162,11 +162,6 @@ return (int)i; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - bool atoi_constrained(const char *str, int *value, const char *name, int min, i= nt max, msglvl_t msglevel) { @@ -194,13 +189,10 @@ return false; } - *value =3D i; + *value =3D (int)i; return true; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif static const char *updatable_options[] =3D { "block-ipv6", "block-outside-= dns", "dhcp-option", "dns", -- 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 Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id440917f433aab1a7db608ba04fa95ba47c2ddde Gerrit-Change-Number: 1153 Gerrit-PatchSet: 5 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newpatchset --cxA3FpJ1de0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld uploaded patch set #5 to this change.

<= p>View C= hange

options: Review use of positive_atoi vs atoi_constrained

R= eplace where it is useful.

While here also add a missing cast in ato= i_constrained.

Change-Id: Id440917f433aab1a7db608ba04fa95ba47c2ddde<= br>Signed-off-by: Frank Lichtenheld <frank@...2641...>
---
M sr= c/openvpn/options.c
M src/openvpn/options_util.c
2 files changed, 22 = insertions(+), 40 deletions(-)

git pull ssh://gerrit.openvpn.net:=
29418/openvpn refs/changes/53/1153/5
diff --git a/src/openvpn/optio=
ns.c b/src/openvpn/options.c
index f801743..5192127 100644<= /span>
--- a/src/openvpn/options.c
+++ b/src/openv= pn/options.c
@@ -7019,21 +7019,15 @@
e= lse 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(msgle= vel, "--tun-mtu-max value '%s' is invalid", p[1]);=
- }
- else
- {
- options->ce.tun_mtu_max =3D max_mtu;- }
+ atoi_constrained(p[1], &optio= ns->ce.tun_mtu_max, p[0], TUN_MTU_MAX_MIN, 65536, msglevel);
<= span> }

else if (streq(p[0], "tun-mtu-extra&q= uot;) && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION);
- options->ce.tun_mtu_extr= a =3D positive_atoi(p[1], msglevel);
- options->ce.tun_mtu_extra_defined =3D true;
+ if (atoi_constrai= ned(p[1], &options->ce.tun_mtu_extra, p[0], 0, 65536, msglevel))

+ {
+ options->ce.tun_mt= u_extra_defined =3D true;
+ }
}
else if (streq(= p[0], "max-packet-size") && p[1] && !p[2])=
{
@@ -7065,11 +7059,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_cons= trained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msglevel))
{
- msg(msglevel, "--fragment needs to be at least 68"= ;);
goto err;
}

@@ -7743,12 +7734,14 @@
= VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);
= if (p[1])
{
- int mssfix =3D positive_atoi(p[1], msgleve= l);
- /* can= be 0, but otherwise it needs to be high enough so we can
- * substract room for heade= rs. */
- if = (mssfix !=3D 0 && (mssfix < TLS_CHANNEL_MTU_MIN || mssfix > U= INT16_MAX))
+ = int mssfix;
+ = if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msgle= vel))
{
- msg(msglevel, "--mssfix value '%s&#= 39; is invalid", p[1]);
+ goto err;
+ }
+ if (mssfix !=3D 0 && mssfix < TLS_CHANNEL_M= TU_MIN)
+ = {
+ ms= g(msglevel, "mssfix needs to be >=3D %d, not %d", TLS_CHANNEL_= MTU_MIN, mssfix);
goto err;
}


@@ -8001,7 +7994,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(po= sitive_atoi(p[1], msglevel), 1);
+ atoi_constrained(p[1], &options->max_routes_per= _client, p[0], 1, INT_MAX, msglevel);
}
else if (streq(p[0], "client-cert-not-required") &&= ; !p[1])

{
@@ -9808,8 +9801,6 @@
}
else if (streq(p[0], "keying-ma= terial-exporter") && p[1] && p[2])
= {
- int ekm_le= ngth =3D positive_atoi(p[2], msglevel);
-
VERIFY_PERMISSION(OPT_P_GENERAL= );

if (strncmp(p[1], "EXPOR= TER", 8))
@@ -9823,14 +9814,14 @@
= msg(msglevel,
"Keying materi= al 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_length,
+ p[0], 16, 4095, msgl= evel))
{
- msg(msglevel, "Invalid keying material exporte= r length");
goto err;
= }

options->keying_mater= ial_exporter_label =3D p[1];
- options->keying_material_exporter_length =3D ekm_length;<= /span>
}
else if (streq(p[0], "allo= w-recursive-routing") && !p[1])
{<= br>@@ -9865,15 +9856,14 @@
}
= else if (streq(p[0], "vlan-pvid") && p[1] && !p= [2])
{
+ int vlan_pvid;
VERIFY_PERMISSION(O= PT_P_GENERAL | OPT_P_INSTANCE);
- options->vlan_pvid =3D positive_atoi(p[1], msglevel);<= /span>
- if (options-&g= t;vlan_pvid < OPENVPN_8021Q_MIN_VID
- || options->vlan_pvid > OPENVPN_8021Q_MA= X_VID)
+ if (!= atoi_constrained(p[1], &vlan_pvid, p[0],
+ OPENVPN_8021Q_MIN_VI= D, OPENVPN_8021Q_MAX_VID, msglevel))
{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(msglevel, "t= he parameter of --vlan-pvid parameters must be >=3D %u and <=3D %u&qu= ot;,

- O= PENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID);
= goto err;
}
+ options->vlan_pvid =3D (uint16_t)vlan_pvid;
}
else
{=
diff --git a/src/openvpn/options_util.c b/src/openvpn/options_uti= l.c
index 8a1c083..2eeecb8 100644
--- a/src= /openvpn/options_util.c
+++ b/src/openvpn/options_util.c
@@ -162,11 +162,6 @@
return (int)i;
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "= ;-Wconversion"

-#e= ndif
-
= bool
atoi_constrained(const char *str, int *value, const = char *name, int min, int max, msglvl_t msglevel)
{<= br>@@ -194,13 +189,10 @@
return false;
}

- *value =3D i;
+ *value =3D (int)i;
return true;=
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif

static const char *updatable_options[] =3D { "block-ipv6", &q= uot;block-outside-dns",

= "dhcp-option", "dns",

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id440917f433aab1a7db608ba04f= a95ba47c2ddde
Gerrit-Change-Number: 1153
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newpatchset
--cxA3FpJ1de0=--