From: "flichtenheld (Code Review)" Date: Fri, 13 Mar 2026 16:39:02 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, gert@...1296... Message-ID: <5bf885a2b7fdf3c2a6b43dfa9e9ac4c148a1ec35-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Rd1I4CV61to="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: init: Fix conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --Rd1I4CV61to= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, plaisthos. Hello cron2, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1259?usp=3Demail to look at the new patch set (#15). The following approvals got outdated and were removed: Code-Review-1 by cron2 Change subject: init: Fix conversion warnings ...................................................................... init: Fix conversion warnings Can be separated in mostly two classes of issues: - Return type of get_random is long, but we ensure that value is in range so we can cast it to whatever we need. - Doing MTU match in size_t even though most of the input values are int. Change-Id: I41b9f7686180f2549bd4984cbbf66059f0ba2b15 Signed-off-by: Frank Lichtenheld --- M src/openvpn/init.c 1 file changed, 17 insertions(+), 25 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/59/1259/15 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 66a5836..a7c13f9 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -454,11 +454,6 @@ } #endif /* ENABLE_MANAGEMENT */ -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - /* * Initialize and possibly randomize the connection list. * @@ -481,7 +476,7 @@ int i; for (i =3D l->len - 1; i > 0; --i) { - const int j =3D get_random() % (i + 1); + const long j =3D get_random() % (i + 1); if (i !=3D j) { struct connection_entry *tmp; @@ -841,7 +836,7 @@ struct timeval tv; if (!gettimeofday(&tv, NULL)) { - const unsigned int seed =3D (unsigned int)tv.tv_sec ^ tv.tv_usec; + const unsigned int seed =3D (unsigned int)(tv.tv_sec ^ tv.tv_usec); srandom(seed); } @@ -2849,7 +2844,7 @@ } } -static size_t +static unsigned int get_frame_mtu(struct context *c, const struct options *o) { size_t mtu; @@ -2870,10 +2865,14 @@ if (mtu < TUN_MTU_MIN) { - msg(M_WARN, "TUN MTU value (%zu) must be at least %d", mtu, TUN_MT= U_MIN); + msg(M_WARN, "TUN MTU value (%zu) must be at least %u", mtu, TUN_MT= U_MIN); frame_print(&c->c2.frame, M_FATAL, "MTU is too small"); } - return mtu; + if (mtu > UINT_MAX) + { + mtu =3D UINT_MAX; + } + return (unsigned int)mtu; } /* @@ -2899,7 +2898,7 @@ * space to allow server to push "baby giant" MTU sizes */ frame->tun_max_mtu =3D max_int(TUN_MTU_MAX_MIN, frame->tun_max_mtu); - size_t payload_size =3D frame->tun_max_mtu; + unsigned int payload_size =3D frame->tun_max_mtu; /* we need to be also large enough to hold larger control channel pack= ets * if configured */ @@ -2918,7 +2917,7 @@ /* the space that is reserved before the payload to add extra headers = to it * we always reserve the space for the worst case */ - size_t headroom =3D 0; + unsigned int headroom =3D 0; /* includes IV and packet ID */ headroom +=3D crypto_max_overhead(); @@ -2942,11 +2941,11 @@ /* the space after the payload, this needs some extra buffer space for * encryption so headroom is probably too much but we do not really ca= re * the few extra bytes */ - size_t tailroom =3D headroom; + unsigned int tailroom =3D headroom; #ifdef USE_COMP msg(D_MTU_DEBUG, - "MTU: adding %zu buffer tailroom for compression for %zu " + "MTU: adding %u buffer tailroom for compression for %u " "bytes of payload", COMP_EXTRA_BUFFER(payload_size), payload_size); tailroom +=3D COMP_EXTRA_BUFFER(payload_size); @@ -3288,18 +3287,15 @@ if (options->renegotiate_seconds_min < 0) { /* Add 10% jitter to reneg-sec by default (server side only) */ - int auto_jitter =3D options->mode !=3D MODE_SERVER - ? 0 - : get_random() % max_int(options->renegotiat= e_seconds / 10, 1); + int jitter_max =3D max_int(options->renegotiate_seconds / 10, 1); + int auto_jitter =3D options->mode !=3D MODE_SERVER ? 0 : (int)(get= _random() % jitter_max); to.renegotiate_seconds =3D options->renegotiate_seconds - auto_jit= ter; } else { /* Add user-specified jitter to reneg-sec */ - to.renegotiate_seconds =3D - options->renegotiate_seconds - - (get_random() - % max_int(options->renegotiate_seconds - options->renegotia= te_seconds_min, 1)); + int jitter_max =3D max_int(options->renegotiate_seconds - options-= >renegotiate_seconds_min, 1); + to.renegotiate_seconds =3D options->renegotiate_seconds - (int)(ge= t_random() % jitter_max); } to.single_session =3D options->single_session; to.mode =3D options->mode; @@ -3491,10 +3487,6 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /* * No encryption or authentication. */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1259?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: I41b9f7686180f2549bd4984cbbf66059f0ba2b15 Gerrit-Change-Number: 1259 Gerrit-PatchSet: 15 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 --Rd1I4CV61to= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: cron2, plaisthos.

flichtenheld uploaded patch set #15 to this change.

=

View = Change

The following approvals got outdated and were removed: Code-Review-1 by cron2

init: Fix conversion warnings
Can be separated in mostly two classes of issues:
- Return type of ge= t_random is long, but we ensure that value
is in range so we can cast= it to whatever we need.
- Doing MTU match in size_t even though most o= f the input
values are int.

Change-Id: I41b9f7686180f2549bd498= 4cbbf66059f0ba2b15
Signed-off-by: Frank Lichtenheld <frank@...2641...= >
---
M src/openvpn/init.c
1 file changed, 17 insertions(+), 25= deletions(-)

git pull ssh://gerrit.openvpn.net:=
29418/openvpn refs/changes/59/1259/15
diff --git a/src/openvpn/init=
.c b/src/openvpn/init.c
index 66a5836..a7c13f9 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.= c
@@ -454,11 +454,6 @@
}
= #endif /* ENABLE_MANAGEMENT */

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pus= h
-#pragma GCC diagnost= ic ignored "-Wconversion"
-#endif
-<= /span>
/*
* Initialize and possibly randomize t= he connection list.
*
@@ -481,7 +476,7 @@=
int i;
for (i =3D l->= len - 1; i > 0; --i)
{
- const int j =3D get_random() % (i = + 1);
+ co= nst long j =3D get_random() % (i + 1);
if (i != =3D j)
{
stru= ct connection_entry *tmp;
@@ -841,7 +836,7 @@
struct timeval tv;

if (!gettimeofday(&tv, = NULL))
{
- const unsigned int seed =3D (unsigned int)tv.tv_sec ^ tv.tv= _usec;
+ const= unsigned int seed =3D (unsigned int)(tv.tv_sec ^ tv.tv_usec);
srandom(seed);

}
=
@@ -2849,7 +2844,7 @@
}
}

-stati= c size_t
+static unsi= gned int
get_frame_mtu(struct context *c, const struct opt= ions *o)
{
size_t mtu;
@@ -2870,10 +2865,14 @@


if (mtu &l= t; TUN_MTU_MIN)
{
- msg(M_WARN, "TUN MTU value (%zu) must be at l= east %d", mtu, TUN_MTU_MIN);
+ msg(M_WARN, "TUN MTU value (%zu) must be at leas= t %u", mtu, TUN_MTU_MIN);
frame_print(&c-= >c2.frame, M_FATAL, "MTU is too small");
= }
- return mtu;
+ if (mtu > UINT_MA= X)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ mtu =3D UINT_MAX;
+ }
+ return (unsigned int)mtu; }

/*
@@ -2899,7 = +2898,7 @@
* space to allow server to push "baby= giant" MTU sizes */
frame->tun_max_mtu =3D ma= x_int(TUN_MTU_MAX_MIN, frame->tun_max_mtu);

= - size_t payload_size =3D fram= e->tun_max_mtu;
+ = unsigned int payload_size =3D frame->tun_max_mtu;

/* we need to be also large enough to hold larger contr= ol channel packets
* if configured */
@@ -2918,7 +2917,7 @@


/* the space = that is reserved before the payload to add extra headers to it
* we always reserve the space for the worst case */

- size_t headroom =3D 0;
+ unsigned int headroom = =3D 0;

/* includes IV and packet ID = */
headroom +=3D crypto_max_overhead();
@@ -2942,11 +2941,11 @@
/* the space after the paylo= ad, this needs some extra buffer space for
* encrypti= on so headroom is probably too much but we do not really care
* the few extra bytes */
- size_t tailroom =3D headroom;
+ unsigned int tailroom =3D headroom;
#ifdef USE_COMP
msg(D_MTU_DE= BUG,
- "MTU= : adding %zu buffer tailroom for compression for %zu "
+ "MTU: adding %u buffer= tailroom for compression for %u "
"byte= s of payload",
COMP_EXTRA_BUFFER(payload_size= ), payload_size);
tailroom +=3D COMP_EXTRA_BUFFER(payl= oad_size);
@@ -3288,18 +3287,15 @@
if = (options->renegotiate_seconds_min < 0)
{<= br> /* Add 10% jitter to reneg-sec by default (server side on= ly) */
- int aut= o_jitter =3D options->mode !=3D MODE_SERVER
- ? 0
- : get_ra= ndom() % max_int(options->renegotiate_seconds / 10, 1);
+ int jitter_max =3D max_int(o= ptions->renegotiate_seconds / 10, 1);
+ int auto_jitter =3D options->mode !=3D MODE= _SERVER ? 0 : (int)(get_random() % jitter_max);
to= .renegotiate_seconds =3D options->renegotiate_seconds - auto_jitter;

}
else
{=
/* Add user-specified jitter to reneg-sec */
<= span style=3D"color: hsl(0, 100%, 40%);">- to.renegotiate_seconds = =3D
- option= s->renegotiate_seconds
- - (get_random()
- % max_int(options->renegotiate_seconds - option= s->renegotiate_seconds_min, 1));
+ int jitter_max =3D max_int(options->renegotiate_= seconds - options->renegotiate_seconds_min, 1);
+ to.renegotiate_seconds =3D options-&= gt;renegotiate_seconds - (int)(get_random() % jitter_max);
= }
to.single_session =3D options->single_sessio= n;
to.mode =3D options->mode;
@@ -3= 491,10 +3487,6 @@
}
}

-#if defined(__GNUC_= _) || defined(__clang__)
-#endif
-=
/*
* No encryption or authentication. */

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

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41b9f7686180f2549bd4984cbbf= 66059f0ba2b15
Gerrit-Change-Number: 1259
Gerrit-PatchSet: 15
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
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-Attention: cron2 <gert@...1296...>= ;
= --Rd1I4CV61to=--