From: "flichtenheld (Code Review)" Date: Wed, 8 Oct 2025 16:12:00 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <59459c86e0ed39369f7987a568ffeca6f4ef2985-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="tAFzV9lhQqg="; 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 --tAFzV9lhQqg= 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 do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1259?usp=3Demail to review the following change. 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, 14 insertions(+), 26 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/59/1259/1 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index f8a0fee..81b9ca9 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -455,11 +455,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. * @@ -482,7 +477,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; @@ -842,7 +837,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); } @@ -2873,17 +2868,17 @@ } } -static size_t +static int get_frame_mtu(struct context *c, const struct options *o) { - size_t mtu; + int mtu; if (o->ce.link_mtu_defined) { ASSERT(o->ce.link_mtu_defined); /* if we have a link mtu defined we calculate what the old code * would have come up with as tun-mtu */ - size_t overhead =3D frame_calculate_protocol_header_size(&c->c1.ks= .key_type, o, true); + int overhead =3D (int)frame_calculate_protocol_header_size(&c->c1.= ks.key_type, o, true); mtu =3D o->ce.link_mtu - overhead; } else @@ -2894,7 +2889,7 @@ 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 (%d) must be at least %d", mtu, TUN_MTU= _MIN); frame_print(&c->c2.frame, M_FATAL, "MTU is too small"); } return mtu; @@ -2923,7 +2918,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; + int payload_size =3D frame->tun_max_mtu; /* we need to be also large enough to hold larger control channel pack= ets * if configured */ @@ -2942,7 +2937,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; + int headroom =3D 0; /* includes IV and packet ID */ headroom +=3D crypto_max_overhead(); @@ -2966,11 +2961,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; + int tailroom =3D headroom; #ifdef USE_COMP msg(D_MTU_DEBUG, - "MTU: adding %zu buffer tailroom for compression for %zu " + "MTU: adding %d buffer tailroom for compression for %d " "bytes of payload", COMP_EXTRA_BUFFER(payload_size), payload_size); tailroom +=3D COMP_EXTRA_BUFFER(payload_size); @@ -3289,18 +3284,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; @@ -3495,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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I41b9f7686180f2549bd4984cbbf66059f0ba2b15 Gerrit-Change-Number: 1259 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --tAFzV9lhQqg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

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 w= hatever we need.
- Doing MTU match in size_t even though most of the in= put
values are int.

Change-Id: I41b9f7686180f2549bd4984cbbf660= 59f0ba2b15
Signed-off-by: Frank Lichtenheld <frank@...2641...>
= ---
M src/openvpn/init.c
1 file changed, 14 insertions(+), 26 deletio= ns(-)

git pull ssh://gerrit.openvpn.net:29418/op=
envpn refs/changes/59/1259/1
diff --git a/src/openvpn/init.c b/src/=
openvpn/init.c
index f8a0fee..81b9ca9 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c<= br>@@ -455,11 +455,6 @@
}
#endif /*= ENABLE_MANAGEMENT */

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push<= br>-#pragma GCC diagnostic ignore= d "-Wconversion"
-#endif
- /*
* Initialize and possibly randomize the connec= tion list.
*
@@ -482,7 +477,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 connec= tion_entry *tmp;
@@ -842,7 +837,7 @@
s= truct 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);
}

@@ -2873,17 +2868,17 @@

}
}
-static size_= t
+static int<= br> get_frame_mtu(struct context *c, const struct options *o)<= br> {
- size_t= mtu;
+ int mtu;

if (o->ce.link_mtu_defined)=
{
ASSERT(o->ce.link_mtu_defined)= ;
/* if we have a link mtu defined we calculate wh= at the old code
* would have come up with as tun-= mtu */
- size_t = overhead =3D frame_calculate_protocol_header_size(&c->c1.ks.key_type= , o, true);
+ = int overhead =3D (int)frame_calculate_protocol_header_size(&c->c1.ks= .key_type, o, true);
mtu =3D o->ce.link_mtu - o= verhead;
}
else
@= @ -2894,7 +2889,7 @@

if (mtu < TU= N_MTU_MIN)
{
- msg(M_WARN, "TUN MTU value (%zu) must be at least = %d", mtu, TUN_MTU_MIN);
+ msg(M_WARN, "TUN MTU value (%d) must be at least %d&q= uot;, mtu, TUN_MTU_MIN);
frame_print(&c->c2= .frame, M_FATAL, "MTU is too small");
}

return mtu;
@@ -2923,7 +2918,7 @@ * space to allow server to push "baby giant" MTU si= zes */
frame->tun_max_mtu =3D max_int(TUN_MTU_MAX_M= IN, frame->tun_max_mtu);

- size_t payload_size =3D frame->tun_max_mtu;<= /span>
+ int payload_size= =3D frame->tun_max_mtu;

/* we ne= ed to be also large enough to hold larger control channel packets * if configured */
@@ -2942,7 +2937,7 @@

/* the space that is reserved before the = payload to add extra headers to it
* we always reserv= e the space for the worst case */
- size_t headroom =3D 0;
+ int headroom =3D 0;

/* includes IV and packet ID */

headroom +=3D c= rypto_max_overhead();
@@ -2966,11 +2961,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 care
* the few extra bytes */
- size_t tailroom =3D hea= droom;
+ int tailr= oom =3D headroom;

#ifdef USE_COMP=
msg(D_MTU_DEBUG,
- "MTU: adding %zu buffer tailroom for compression for= %zu "
+ = "MTU: adding %d buffer tailroom for compression for %d " "bytes of payload",
COM= P_EXTRA_BUFFER(payload_size), payload_size);
tailroom = +=3D COMP_EXTRA_BUFFER(payload_size);
@@ -3289,18 +3284,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->renegotiate_seconds= / 10, 1);
+ i= nt jitter_max =3D max_int(options->renegotiate_seconds / 10, 1);<= br>+ int auto_jitter =3D= options->mode !=3D MODE_SERVER ? 0 : (int)(get_random() % jitter_max);<= /span>
to.renegotiate_seconds =3D options->renegotiate= _seconds - auto_jitter;
}
else
{
/* Add user-specified jitter = to reneg-sec */
- = to.renegotiate_seconds =3D
- options->renegotiate_seconds
- - (get_random()
- % max_int(options->ren= egotiate_seconds - options->renegotiate_seconds_min, 1));
+ int jitter_max =3D max_int= (options->renegotiate_seconds - options->renegotiate_seconds_min, 1);=

+ to.renegoti= ate_seconds =3D options->renegotiate_seconds - (int)(get_random() % jitt= er_max);
}
to.single_session =3D = options->single_session;
to.mode =3D options->mo= de;
@@ -3495,10 +3487,6 @@
} }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/*
* No encryption or= authentication.
*/

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

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41b9f7686180f2549bd4984cbbf= 66059f0ba2b15
Gerrit-Change-Number: 1259
Gerrit-PatchSet: 1
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...>
= --tAFzV9lhQqg=--