]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
ssl: Clean up type handling in export_user_keying_material()
authorFrank Lichtenheld <frank@lichtenheld.com>
Thu, 30 Oct 2025 14:52:26 +0000 (15:52 +0100)
committerGert Doering <gert@greenie.muc.de>
Mon, 17 Nov 2025 07:38:54 +0000 (08:38 +0100)
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 <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1301
Message-Id: <20251030145231.2792-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34036.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/buffer.c
src/openvpn/buffer.h
src/openvpn/ssl.c

index 28de00fdb65e52b937859c1e1924a198cc0d4cea..293622f98b612eedb08fe4ab10ce4f608f81e4e4 100644 (file)
@@ -480,18 +480,17 @@ gc_transfer(struct gc_arena *dest, struct gc_arena *src)
  */
 
 char *
-format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int space_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 = space_break_flags & FHE_SPACE_BREAK_MASK;
     const size_t separator_len = separator ? strlen(separator) : 0;
-    static_assert(INT_MAX <= SIZE_MAX, "Code assumes INT_MAX <= SIZE_MAX");
     const size_t out_len = maxoutput > 0
                                ? maxoutput
                                : ((size * 2) + ((size / bytes_per_hexblock) * separator_len) + 2);
 
     struct buffer out = alloc_buf_gc(out_len, gc);
-    for (int i = 0; i < size; ++i)
+    for (size_t i = 0; i < size; ++i)
     {
         if (separator && i && !(i % bytes_per_hexblock))
         {
index 148cee061037091552b5ef3e0fcdfae6e2e1cff4..ab2a29dc95aae3dbb4ea437c4c04c2676d7a3930 100644 (file)
@@ -496,11 +496,11 @@ bool buf_parse(struct buffer *buf, const int delim, char *line, const int size);
  */
 #define FHE_SPACE_BREAK_MASK 0xFF  /* space_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 maxoutput, unsigned int space_break_flags,
+char *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);
 
 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_arena *gc)
 {
     return format_hex_ex(data, size, maxoutput, 4, " ", gc);
 }
index 22a1f5251b081fe8ee4c91632c468363203e98d3..48418372ad51b660bb851fec9cf2493237f0429c 100644 (file)
@@ -1829,11 +1829,6 @@ read_string(struct buffer *buf, char *str, const unsigned int capacity)
     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 @@ export_user_keying_material(struct tls_session *session)
 {
     if (session->opt->ekm_size > 0)
     {
-        unsigned int size = session->opt->ekm_size;
+        const size_t size = session->opt->ekm_size;
         struct gc_arena gc = gc_new();
 
-        unsigned char *ekm = gc_malloc(session->opt->ekm_size, true, &gc);
+        unsigned char *ekm = 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 = (size * 2) + 2;
+            const size_t len = (size * 2) + 2;
 
             const char *key = format_hex_ex(ekm, size, len, 0, NULL, &gc);
             setenv_str(session->opt->es, "exported_keying_material", key);
@@ -2199,6 +2194,11 @@ export_user_keying_material(struct tls_session *session)
     }
 }
 
+#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).