From: "flichtenheld (Code Review)"
Date: Mon, 3 Nov 2025 12:03:24 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, gert@...1296...
Message-ID:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="E9UvAEXdupc="; charset=UTF-8
Subject: [Openvpn-devel] [S] Change in openvpn[master]: ssl: Clean up type
handling in export_user_keying_material()
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos
Cc: openvpn-devel
--E9UvAEXdupc=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: flichtenheld, plaisthos.
Hello cron2, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1301?usp=3Demail
to look at the new patch set (#4).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied=
now.
Change subject: ssl: Clean up type handling in export_user_keying_material()
......................................................................
ssl: Clean up type handling in export_user_keying_material()
For this we actually change the API of the
format_hex{,_ex} functions by changing int
to size_t for length parameters. While we
call this function with int paramters in
a lot of places (usually BLEN), this will
not produce warnings under
-Wno-sign-conversion. And we're sure those
values are positive since format_hex already
uses size_t internally.
Change-Id: Id7bacec23edc6dcd94465c308ea2144c7329a0c1
Signed-off-by: Frank Lichtenheld
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/ssl.c
3 files changed, 12 insertions(+), 13 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/01/1301/4
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index 28de00f..293622f 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -480,18 +480,17 @@
*/
char *
-format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int s=
pace_break_flags,
+format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, unsigned=
int space_break_flags,
const char *separator, struct gc_arena *gc)
{
const size_t bytes_per_hexblock =3D space_break_flags & FHE_SPACE_BREA=
K_MASK;
const size_t separator_len =3D separator ? strlen(separator) : 0;
- static_assert(INT_MAX <=3D SIZE_MAX, "Code assumes INT_MAX <=3D SIZE_M=
AX");
const size_t out_len =3D maxoutput > 0
? maxoutput
: ((size * 2) + ((size / bytes_per_hexblock=
) * separator_len) + 2);
struct buffer out =3D alloc_buf_gc(out_len, gc);
- for (int i =3D 0; i < size; ++i)
+ for (size_t i =3D 0; i < size; ++i)
{
if (separator && i && !(i % bytes_per_hexblock))
{
diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 148cee0..ab2a29d 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -496,11 +496,11 @@
*/
#define FHE_SPACE_BREAK_MASK 0xFF /* space_break parameter in lower 8 bit=
s */
#define FHE_CAPS 0x100 /* output hex in caps */
-char *format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned=
int space_break_flags,
+char *format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, un=
signed int space_break_flags,
const char *separator, struct gc_arena *gc);
static inline char *
-format_hex(const uint8_t *data, int size, int maxoutput, struct gc_arena *=
gc)
+format_hex(const uint8_t *data, size_t size, size_t maxoutput, struct gc_a=
rena *gc)
{
return format_hex_ex(data, size, maxoutput, 4, " ", gc);
}
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index e03b81e..73d1215 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -1829,11 +1829,6 @@
return len;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
static char *
read_string_alloc(struct buffer *buf)
{
@@ -2174,15 +2169,15 @@
{
if (session->opt->ekm_size > 0)
{
- unsigned int size =3D session->opt->ekm_size;
+ const size_t size =3D session->opt->ekm_size;
struct gc_arena gc =3D gc_new();
- unsigned char *ekm =3D gc_malloc(session->opt->ekm_size, true, &gc=
);
+ unsigned char *ekm =3D gc_malloc(size, true, &gc);
if (key_state_export_keying_material(session, session->opt->ekm_la=
bel,
session->opt->ekm_label_size,=
ekm,
session->opt->ekm_size))
{
- unsigned int len =3D (size * 2) + 2;
+ const size_t len =3D (size * 2) + 2;
const char *key =3D format_hex_ex(ekm, size, len, 0, NULL, &gc=
);
setenv_str(session->opt->es, "exported_keying_material", key);
@@ -2199,6 +2194,11 @@
}
}
+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
+
/**
* Handle reading key data, peer-info, username/password, OCC
* from the TLS control channel (cleartext).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1301?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: Id7bacec23edc6dcd94465c308ea2144c7329a0c1
Gerrit-Change-Number: 1301
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: cron2
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-Attention: flichtenheld
--E9UvAEXdupc=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: flichtenheld, plaisthos.
flichtenheld uploaded patch set #4 to this change.
<=
p>View C=
hange
The change is no longer submittable: checks~ChecksSubmitRul=
e is unsatisfied now.
ssl: Clean up type handling in expor=
t_user_keying_material()
For this we actually change the API of the<=
br>format_hex{,_ex} functions by changing int
to size_t for length param=
eters. While we
call this function with int paramters in
a lot of pla=
ces (usually BLEN), this will
not produce warnings under
-Wno-sign-co=
nversion. And we're sure those
values are positive since format_hex =
already
uses size_t internally.
Change-Id: Id7bacec23edc6dcd94465=
c308ea2144c7329a0c1
Signed-off-by: Frank Lichtenheld <frank@...2723...=
.>
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/o=
penvpn/ssl.c
3 files changed, 12 insertions(+), 13 deletions(-)
<=
/pre>git pull ssh://gerrit.openvpn.net:29418/openvpn refs/cha=
nges/01/1301/4
diff --git a/src/openvpn/buffer.c b/src/openvpn/buff=
er.c
index 28de00f..293622f 100644
--- a/sr=
c/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -480,18 +480,17 @@
*/
<=
span> char *
-format_he=
x_ex(const uint8_t *data, int size, int maxoutput, unsigned int space_break=
_flags,
+format_hex_e=
x(const uint8_t *data, size_t size, size_t maxoutput, unsigned int space_br=
eak_flags,
const char *separator, struct gc_=
arena *gc)
{
const size_t bytes_per_h=
exblock =3D space_break_flags & FHE_SPACE_BREAK_MASK;
=
const size_t separator_len =3D separator ? strlen(separator) : 0;
- static_assert(INT_MAX &=
lt;=3D SIZE_MAX, "Code assumes INT_MAX <=3D SIZE_MAX");=
const size_t out_len =3D maxoutput > 0
=
? maxoutput
=
: ((size * 2) + ((size / bytes_per_hexblock) * separator_len=
) + 2);
struct buffer out =3D alloc_=
buf_gc(out_len, gc);
- =
for (int i =3D 0; i < size; ++i)
+ for (size_t i =3D 0; i < size; ++i)
{
if (separator && i && !(=
i % bytes_per_hexblock))
{
diff --=
git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 148=
cee0..ab2a29d 100644
--- a/src/openvpn/buffer.h
<=
span>+++ b/src/openvpn/buffer.h
@@ -496,11 +496,11 @@
*/
#define FHE_SPACE_BREAK_MASK 0xFF /* spac=
e_break parameter in lower 8 bits */
#define FHE_CAPS =
0x100 /* output hex in caps */
-char *format_hex_ex(const uint8_t *data, int size, int max=
output, unsigned int space_break_flags,
+char *format_hex_ex(const uint8_t *data, size_t size, s=
ize_t maxoutput, unsigned int space_break_flags,
=
const char *separator, struct gc_arena *gc);
=
span>
static inline char *
-format_hex(const uint8_t *data, int size, int maxoutput, str=
uct gc_arena *gc)
+fo=
rmat_hex(const uint8_t *data, size_t size, size_t maxoutput, struct gc_aren=
a *gc)
{
return format_hex_ex(data, s=
ize, maxoutput, 4, " ", gc);
}
d=
iff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index e03=
b81e..73d1215 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -1829,11 +1829,6 @@
=
return len;
}
-#if defined(__GNUC__) || defined(__cl=
ang__)
-#pragma GCC dia=
gnostic push
-#pragma G=
CC diagnostic ignored "-Wconversion"
-#endif
-
static char *
read_string_allo=
c(struct buffer *buf)
{
@@ -2174,15 +2169,=
15 @@
{
if (session->opt->ekm_s=
ize > 0)
{
- unsigned int size =3D session->opt->ekm_size;
+ const size_t s=
ize =3D session->opt->ekm_size;
struct gc_ar=
ena gc =3D gc_new();
- unsigned char *ekm =3D gc_malloc(session->opt-&=
gt;ekm_size, true, &gc);
+ unsigned char *ekm =3D gc_malloc(size, true, &gc);
if (key_state_export_keying_material(session, session=
->opt->ekm_label,
=
session->opt->ekm_label_size, ekm,
=
session->opt->ekm_size))
{
-=
unsigned int len =3D (size * 2) + 2;
+ const size_t len =3D (size * 2) + =
2;
const char *key =3D forma=
t_hex_ex(ekm, size, len, 0, NULL, &gc);
se=
tenv_str(session->opt->es, "exported_keying_material", key)=
;
@@ -2199,6 +2194,11 @@
}
<=
span> }
+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "=
-Wconversion"
+#=
endif
+
/**
* Handle reading key data, peer-info, username/pa=
ssword, OCC
* from the TLS control channel (cleartext).=
span>
To view, visit change 1301. To unsubscribe, =
or for help writing mail filters, visit settings.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id7bacec23edc6dcd94465c308ea=
2144c7329a0c1
Gerrit-Change-Number: 1301
Gerrit-PatchSet: 4
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: flichtenheld <frank@...2375...=
41...>
=
--E9UvAEXdupc=--