[Openvpn-devel,v4] socket_util: Clean up conversion warnings in add_in6_addr

Message ID 20250831151259.25788-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v4] socket_util: Clean up conversion warnings in add_in6_addr | expand

Commit Message

Gert Doering Aug. 31, 2025, 3:12 p.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

Change-Id: Id3b8719ee6b457ce2d85156b39e0cea771a97e74
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
---

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/+/1161
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <gert@greenie.muc.de>

Comments

Gert Doering Aug. 31, 2025, 4:50 p.m. UTC | #1
The patch itself is straight forward, but having a unit test for all
the possible overflows is very welcome - "it will test itself, across
all platforms".  BB is all green, local test on Linux also passes.

Your patch has been applied to the master branch.

commit 84ef4848e7c7325759c67a1bfee231e13efe9f89
Author: Frank Lichtenheld
Date:   Sun Aug 31 17:12:52 2025 +0200

     socket_util: Clean up conversion warnings in add_in6_addr

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20250831151259.25788-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32725.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/socket_util.c b/src/openvpn/socket_util.c
index 13f8c32..9b7312d 100644
--- a/src/openvpn/socket_util.c
+++ b/src/openvpn/socket_util.c
@@ -241,14 +241,12 @@ 
 struct in6_addr
 add_in6_addr(struct in6_addr base, uint32_t add)
 {
-    int i;
-
-    for (i = 15; i >= 0 && add > 0; i--)
+    for (int i = 15; i >= 0 && add > 0; i--)
     {
-        register int carry;
+        register uint32_t carry;
         register uint32_t h;
 
-        h = (unsigned char)base.s6_addr[i];
+        h = base.s6_addr[i];
         base.s6_addr[i] = (h + add) & UINT8_MAX;
 
         /* using explicit carry for the 8-bit additions will catch