[Openvpn-devel,v1] push_util: Fix conversion warnings

Message ID 20251018170237.21928-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v1] push_util: Fix conversion warnings | expand

Commit Message

Gert Doering Oct. 18, 2025, 5:02 p.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

Mostly just use better types.

Change-Id: I4113d14c6ce33818573b0ca5857a9ab39b35a8f4
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: mrbff <marco@mandelbit.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1283
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1283
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
mrbff <marco@mandelbit.com>

Comments

Gert Doering Oct. 18, 2025, 6:03 p.m. UTC | #1
Smoke tested ("does it compile and pass client side tests").  Still no
real testbed for PUSH_UPDATE, alas.  Marco says it's fine, and it's his
code, and BB agrees, forward we move ;-)

Application of the patch needed a bit of pressure because quite a bit
of context has changed in the meantime (commit 5e4c9a69eaf) - but only
context, no affected code itself.

Your patch has been applied to the master branch.

commit a8b8e41c7906c895ba6c88aa748e6dfa3946aff5
Author: Frank Lichtenheld
Date:   Sat Oct 18 19:02:32 2025 +0200

     push_util: Fix conversion warnings

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: mrbff <marco@mandelbit.com>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1283
     Message-Id: <20251018170237.21928-1-gert@greenie.muc.de>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59248341/
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/push_util.c b/src/openvpn/push_util.c
index 06b4c8b..8c1a503 100644
--- a/src/openvpn/push_util.c
+++ b/src/openvpn/push_util.c
@@ -10,18 +10,13 @@ 
 #include "ssl_util.h"
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 int
 process_incoming_push_update(struct context *c, unsigned int permission_mask,
                              unsigned int *option_types_found, struct buffer *buf,
                              bool msg_sender)
 {
     int ret = PUSH_MSG_ERROR;
-    const uint8_t ch = buf_read_u8(buf);
+    const int ch = buf_read_u8(buf);
     if (ch == ',')
     {
         if (apply_push_options(c, &c->options, buf, permission_mask, option_types_found, c->c2.es,
@@ -57,8 +52,8 @@ 
  * Return index of last `,` or `0` if it didn't find any.
  * If there is a comma at index `0` it's an error anyway
  */
-static int
-find_first_comma_of_next_bundle(const char *str, int ix)
+static size_t
+find_first_comma_of_next_bundle(const char *str, size_t ix)
 {
     while (ix > 0)
     {
@@ -75,8 +70,8 @@ 
 static struct buffer
 forge_msg(const char *src, const char *continuation, struct gc_arena *gc)
 {
-    int src_len = strlen(src);
-    int con_len = continuation ? strlen(continuation) : 0;
+    size_t src_len = strlen(src);
+    size_t con_len = continuation ? strlen(continuation) : 0;
     struct buffer buf = alloc_buf_gc(src_len + sizeof(push_update_cmd) + con_len + 2, gc);
 
     buf_printf(&buf, "%s,%s%s", push_update_cmd, src, continuation ? continuation : "");
@@ -93,11 +88,11 @@ 
     return ret;
 }
 
-/* It split the messagge (if necessay) and fill msgs with the message chunks.
+/* It split the messagge (if necessary) and fill msgs with the message chunks.
  * Return `false` on failure an `true` on success.
  */
 static bool
-message_splitter(const char *s, struct buffer *msgs, struct gc_arena *gc, const int safe_cap)
+message_splitter(const char *s, struct buffer *msgs, struct gc_arena *gc, const size_t safe_cap)
 {
     if (!s || !*s)
     {
@@ -105,7 +100,7 @@ 
     }
 
     char *str = gc_strdup(s, gc);
-    int i = 0;
+    size_t i = 0;
     int im = 0;
 
     while (*str)
@@ -113,7 +108,7 @@ 
         /* + ',' - '/0' */
         if (strlen(str) > safe_cap)
         {
-            int ci = find_first_comma_of_next_bundle(str, safe_cap);
+            size_t ci = find_first_comma_of_next_bundle(str, safe_cap);
             if (!ci)
             {
                 /* if no commas were found go to fail, do not send any message */
@@ -219,7 +214,7 @@ 
  * @return The number of clients to which the message was sent. Might return < 0 in case of error.
  */
 static int
-send_push_update(struct multi_context *m, const void *target, const char *msg, const push_update_type type, const int push_bundle_size)
+send_push_update(struct multi_context *m, const void *target, const char *msg, const push_update_type type, const size_t push_bundle_size)
 {
     if (dco_enabled(&m->top.options))
     {
@@ -228,19 +223,19 @@ 
         return 0;
     }
 
-    if (!msg || !*msg || !m
-        || (!target && type != UPT_BROADCAST))
+    if (!msg || !*msg || !m || (!target && type != UPT_BROADCAST))
     {
         return -EINVAL;
     }
 
     struct gc_arena gc = gc_new();
     /* extra space for possible trailing ifconfig and push-continuation */
-    const int extra = 84 + sizeof(push_update_cmd);
+    const size_t extra = 84 + sizeof(push_update_cmd);
     /* push_bundle_size is the maximum size of a message, so if the message
      * we want to send exceeds that size we have to split it into smaller messages */
-    const int safe_cap = push_bundle_size - extra;
-    int msgs_num = (strlen(msg) / safe_cap) + ((strlen(msg) % safe_cap) != 0);
+    ASSERT(push_bundle_size > extra);
+    const size_t safe_cap = push_bundle_size - extra;
+    size_t msgs_num = (strlen(msg) / safe_cap) + ((strlen(msg) % safe_cap) != 0);
     struct buffer *msgs = gc_malloc((msgs_num + 1) * sizeof(struct buffer), true, &gc);
 
     unsigned int option_types_found = 0;
@@ -354,7 +349,3 @@ 
     RETURN_UPDATE_STATUS(n_sent);
 }
 #endif /* ifdef ENABLE_MANAGEMENT */
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif