From: "flichtenheld (Code Review)" Date: Wed, 26 Nov 2025 14:45:50 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <2e251ec239bbcd3e7b7d641b1bd6ebc4d0c5b2c2-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="P1iD6T/9DA0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: packet_id: Avoid conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --P1iD6T/9DA0= 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/+/1407?usp=3Demail to review the following change. Change subject: packet_id: Avoid conversion warnings ...................................................................... packet_id: Avoid conversion warnings Most of these already have checks that the values are as expected, so we can just add the required casts. Only the circ list x_sizeof is changed to size_t since that is its purpose (and it is not actually used anyway). Change-Id: Ib0584e8728701cca10ac5675c9cb0e6f5eb901ac Signed-off-by: Frank Lichtenheld --- M src/openvpn/circ_list.h M src/openvpn/packet_id.c M src/openvpn/packet_id.h 3 files changed, 21 insertions(+), 37 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1407/1 diff --git a/src/openvpn/circ_list.h b/src/openvpn/circ_list.h index eebf087..12f2bea 100644 --- a/src/openvpn/circ_list.h +++ b/src/openvpn/circ_list.h @@ -33,7 +33,7 @@ int x_head; \ int x_size; \ int x_cap; \ - int x_sizeof; \ + size_t x_sizeof; \ type x_list[]; \ } @@ -58,14 +58,14 @@ (obj)->x_size =3D 0; \ } -#define CIRC_LIST_ALLOC(dest, list_type, size) = \ - { = \ - const int so =3D sizeof(list_type) + sizeof((dest)->x_list[0]) * (= size); \ - (dest) =3D (list_type *)malloc(so); = \ - check_malloc_return(dest); = \ - memset((dest), 0, so); = \ - (dest)->x_cap =3D size; = \ - (dest)->x_sizeof =3D so; = \ +#define CIRC_LIST_ALLOC(dest, list_type, size) = \ + { = \ + const size_t so =3D sizeof(list_type) + sizeof((dest)->x_list[0]) = * (size); \ + (dest) =3D (list_type *)malloc(so); = \ + check_malloc_return(dest); = \ + memset((dest), 0, so); = \ + (dest)->x_cap =3D size; = \ + (dest)->x_sizeof =3D so; = \ } #define CIRC_LIST_FREE(dest) free(dest) diff --git a/src/openvpn/packet_id.c b/src/openvpn/packet_id.c index 08d9d9b..12525d1 100644 --- a/src/openvpn/packet_id.c +++ b/src/openvpn/packet_id.c @@ -71,11 +71,6 @@ #endif } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static void packet_id_init_recv(struct packet_id_rec *rec, int seq_backtrack, int time= _backtrack, const char *name, int unit) @@ -119,7 +114,7 @@ /* Reinitalise the source */ CLEAR(*src); - packet_id_init_recv(src, dest->seq_backtrack, dest->time_backtrack, de= st->name, dest->unit); + packet_id_init_recv(src, (int)dest->seq_backtrack, dest->time_backtrac= k, dest->name, dest->unit); } void @@ -170,7 +165,7 @@ diff =3D p->id - pin->id; if (diff < CIRC_LIST_SIZE(p->seq_list) && local_now > SEQ_EXPIRED) { - CIRC_LIST_ITEM(p->seq_list, diff) =3D local_now; + CIRC_LIST_ITEM(p->seq_list, (int)diff) =3D local_now; } } else @@ -264,7 +259,7 @@ } { - const time_t v =3D CIRC_LIST_ITEM(p->seq_list, diff); + const time_t v =3D CIRC_LIST_ITEM(p->seq_list, (int)diff); if (v =3D=3D 0) { return true; @@ -386,7 +381,7 @@ return false; } - const packet_id_type net_id =3D htonpid(p->id); + const packet_id_type net_id =3D htonpid((packet_id_type)p->id); const net_time_t net_time =3D htontime(p->time); if (prepend) { @@ -640,7 +635,7 @@ p->seq_backtrack, p->time_backtrack, p->max_backtrack_stat,= (int)p->initialized); if (sl !=3D NULL) { - buf_printf(&out, " sl=3D[%d,%d,%d,%d]", sl->x_head, sl->x_size, sl= ->x_cap, sl->x_sizeof); + buf_printf(&out, " sl=3D[%d,%d,%d,%zu]", sl->x_head, sl->x_size, s= l->x_cap, sl->x_sizeof); } @@ -655,7 +650,6 @@ { uint64_t packet_id; - if (!buf_read(buf, &packet_id, sizeof(packet_id))) { return 0; @@ -663,16 +657,12 @@ uint64_t id =3D ntohll(packet_id); /* top most 16 bits */ - uint16_t epoch =3D id >> 48; + uint16_t epoch =3D (uint16_t)(id >> 48); pin->id =3D id & PACKET_ID_MASK; return epoch; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - bool packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, struct buf= fer *buf) { diff --git a/src/openvpn/packet_id.h b/src/openvpn/packet_id.h index e9d3647..cdc734d 100644 --- a/src/openvpn/packet_id.h +++ b/src/openvpn/packet_id.h @@ -280,26 +280,20 @@ return p->fd >=3D 0; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - -/* transfer packet_id -> packet_id_persist */ +/* transfer packet_id -> packet_id_persist + Note: Only supported for non-epoch format (i.e. 32bit ID, not 64bit for= mat), + must be enforced at the caller. + */ static inline void packet_id_persist_save_obj(struct packet_id_persist *p, const struct packe= t_id *pid) { - if (packet_id_persist_enabled(p) && pid->rec.time) + if (packet_id_persist_enabled(p) && pid->rec.time && pid->rec.id <=3D = PACKET_ID_MAX) { p->time =3D pid->rec.time; - p->id =3D pid->rec.id; + p->id =3D (packet_id_type)pid->rec.id; } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /** * Reset the current send packet id to its initial state. * Use very carefully (e.g. in the standalone reset packet context) to -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1407?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: Ib0584e8728701cca10ac5675c9cb0e6f5eb901ac Gerrit-Change-Number: 1407 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --P1iD6T/9DA0= 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

packet_id: Avoid conversion warnings
Most of these already have checks that the
values are as expected, so w= e can just add
the required casts.

Only the circ list x_sizeof is= changed to
size_t since that is its purpose (and it is
not actually = used anyway).

Change-Id: Ib0584e8728701cca10ac5675c9cb0e6f5eb901acSigned-off-by: Frank Lichtenheld <frank@...2641...>
---
M src= /openvpn/circ_list.h
M src/openvpn/packet_id.c
M src/openvpn/packet_i= d.h
3 files changed, 21 insertions(+), 37 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1= 407/1
diff --git a/src/openvpn/circ_list.h b/src/openvpn/circ_list.=
h
index eebf087..12f2bea 100644
--- a/src/o= penvpn/circ_list.h
+++ b/src/openvpn/circ_list.h
= @@ -33,7 +33,7 @@
int x_head; \
int x_size; \
int= x_cap; \
- = int x_sizeof; \
+ size_t x_sizeof; \
type x_= list[]; \
}

@= @ -58,14 +58,14 @@
(obj)->x_size =3D 0; \
}

-#define CIRC_LIST_ALLOC(dest, list_type, size) = \
-= { = \
- const in= t so =3D sizeof(list_type) + sizeof((dest)->x_list[0]) * (size); \
- (dest) =3D (list_ty= pe *)malloc(so); \
- check_malloc_return(dest); = \
- memset((dest), 0, so); = \
- (dest)->x_cap =3D size; = \
- (= dest)->x_sizeof =3D so; = \
+#define CIRC_LIST_= ALLOC(dest, list_type, size) \+ { = \
+ const size_t so =3D sizeof(list_= type) + sizeof((dest)->x_list[0]) * (size); \
+ (dest) =3D (list_type *)malloc(so); = \
+ check_malloc_return(dest); = \
+ memset((dest), 0, so); = \
+ = (dest)->x_cap =3D size; = \
+ = (dest)->x_sizeof =3D so; = \
}

#define CIR= C_LIST_FREE(dest) free(dest)
diff --git a/src/openvpn/packe= t_id.c b/src/openvpn/packet_id.c
index 08d9d9b..12525d1 100= 644
--- a/src/openvpn/packet_id.c
+++ b/src= /openvpn/packet_id.c
@@ -71,11 +71,6 @@
#e= ndif
}

-#if defined(__GNUC__) || defined(__clang__)
<= span style=3D"color: hsl(0, 100%, 40%);">-#pragma GCC diagnostic push
-#pragma GCC diagnostic igno= red "-Wconversion"
-#endif
-<= br> static void
packet_id_init_recv(struct packet_id= _rec *rec, int seq_backtrack, int time_backtrack,
= const char *name, int unit)
@@ -119,7 +114,7 @@=

/* Reinitalise the source */=
CLEAR(*src);
- packet_id_init_recv(src, dest->seq_backtrack, dest->time_ba= cktrack, dest->name, dest->unit);
+ packet_id_init_recv(src, (int)dest->seq_backtrac= k, dest->time_backtrack, dest->name, dest->unit);
= }

void
@@ -170,7 +165,7= @@
diff =3D p->id - pin->id;
if (diff < CIRC_LIST_SIZE(p->seq_list) && local_no= w > SEQ_EXPIRED)

{
- CIRC_LIST_ITEM(p->seq_list, diff) = =3D local_now;
+ = CIRC_LIST_ITEM(p->seq_list, (int)diff) =3D local_now;
<= span> }

}
else
= @@ -264,7 +259,7 @@
}
<= /span>
{
- const time_t v =3D CIRC_LIST_ITEM(p->seq_list, = diff);
+ = const time_t v =3D CIRC_LIST_ITEM(p->seq_list, (int)diff);
= if (v =3D=3D 0)
{
return true;
@@ -386,7 = +381,7 @@
return false;
}

- con= st packet_id_type net_id =3D htonpid(p->id);
+ const packet_id_type net_id =3D htonpid((pa= cket_id_type)p->id);
const net_time_t net_time =3D = htontime(p->time);
if (prepend)
= {
@@ -640,7 +635,7 @@
p-&= gt;seq_backtrack, p->time_backtrack, p->max_backtrack_stat, (int)p-&g= t;initialized);
if (sl !=3D NULL)
= {
- buf_printf(= &out, " sl=3D[%d,%d,%d,%d]", sl->x_head, sl->x_size, sl= ->x_cap, sl->x_sizeof);
+ buf_printf(&out, " sl=3D[%d,%d,%d,%zu]", sl= ->x_head, sl->x_size, sl->x_cap, sl->x_sizeof);
}



@@ -655,7 +650,= 6 @@
{
uint64_t packet_id;
=
-
if (!buf_read(buf, &packet_id, sizeof(packet_id)))

{

return 0;
@@ -663,16 +6= 57,12 @@

uint64_t id =3D ntohll(pack= et_id);
/* top most 16 bits */
- uint16_t epoch =3D id >> 48;
+ uint16_t epoch =3D (= uint16_t)(id >> 48);

pin->i= d =3D id & PACKET_ID_MASK;
return epoch; }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
bool
packet_id_write_e= poch(struct packet_id_send *p, uint16_t epoch, struct buffer *buf) {
diff --git a/src/openvpn/packet_id.h b/src/openv= pn/packet_id.h
index e9d3647..cdc734d 100644
--- a/src/openvpn/packet_id.h

+++ b/src/openvpn/packet_id= .h
@@ -280,26 +280,20 @@
return p->= fd >=3D 0;
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic p= ush
-#pragma GCC diagno= stic ignored "-Wconversion"
-#endif
= -
-/* transfer packet_i= d -> packet_id_persist */
+/* transfer packet_id -> packet_id_persist
+ Note: Only supported for non-epoch fo= rmat (i.e. 32bit ID, not 64bit format),
+ must be enforced at the caller.
+ */
static inline void<= /span>
packet_id_persist_save_obj(struct packet_id_persist *p, co= nst struct packet_id *pid)
{
- if (packet_id_persist_enabled(p) && pid= ->rec.time)
+ i= f (packet_id_persist_enabled(p) && pid->rec.time && pid-= >rec.id <=3D PACKET_ID_MAX)
{
= p->time =3D pid->rec.time;
- p->id =3D pid->rec.id;
+ p->id =3D (packet_id_type)pid= ->rec.id;
}
}

-#if defined(__GNUC__) ||= defined(__clang__)
-#p= ragma GCC diagnostic pop
-
<= span> /**

* Reset the current send packet id to its initi= al state.
* Use very carefully (e.g. in the standalone re= set packet context) to

To view, visit <= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1407?usp=3Demail">change 14= 07. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib0584e8728701cca10ac5675c9c= b0e6f5eb901ac
Gerrit-Change-Number: 1407
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...>
= --P1iD6T/9DA0=--