Skip to contentSkip to conversation

Change in openvpn[master]: ssl: Avoid sign-compare warning in should_trigger_renegotiation

Openvpn-devel flichtenheld (Code Review) 1 participant 3 messages Feb 13 – Apr 1 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1771008284000.I701452496bb47c58b9728b08104dd5cb7823a94f@...2715...

#1 lore raw

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/+/1526?usp=email

to review the following change.

Change subject: ssl: Avoid sign-compare warning in should_trigger_renegotiation
......................................................................

ssl: Avoid sign-compare warning in should_trigger_renegotiation

Check that the value is positive and then cast it
to counter_type.

Change-Id I701452496bb47c58b9728b08104dd5cb7823a94f

---
M src/openvpn/ssl.c

1 file changed, 2 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/26/1526/1

src/openvpn/ssl.c +2 -11
index aac31c2..b053dbf 100644
@@ -2909,11 +2909,6 @@
     return true;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 /**
  * Determines if a renegotiation should be triggerred based on the various
  * factors that can trigger one
@@ -2929,13 +2924,13 @@
     }
 
     /* Byte limit */
-    if (session->opt->renegotiate_bytes > 0 && ks->n_bytes >= session->opt->renegotiate_bytes)
+    if (session->opt->renegotiate_bytes > 0 && ks->n_bytes >= (counter_type)session->opt->renegotiate_bytes)
     {
         return true;
     }
 
     /* Packet limit */
-    if (session->opt->renegotiate_packets && ks->n_packets >= session->opt->renegotiate_packets)
+    if (session->opt->renegotiate_packets > 0 && ks->n_packets >= (counter_type)session->opt->renegotiate_packets)
     {
         return true;
     }
@@ -2993,10 +2988,6 @@
     return false;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * This is the primary routine for processing TLS stuff inside the
  * the main event loop.  When this routine exits

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1526?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I701452496bb47c58b9728b08104dd5cb7823a94f
Gerrit-Change-Number: 1526
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1526?usp=email )

Change subject: ssl: Avoid sign-compare warning in should_trigger_renegotiation
......................................................................

Patch Set 7: Code-Review-1

Copied votes on follow-up patch sets have been updated:
* Code-Review-1 has been copied to patch set 8 (copy condition: "changekind:NO_CHANGE OR changekind:TRIVIAL_REBASE OR is:MIN").

(1 comment)

File src/openvpn/ssl.c:

http://gerrit.openvpn.net/c/openvpn/+/1526/comment/6043bf12_8e71cece?usp=email :
PS7, Line 2927: if (session->opt->renegotiate_bytes > 0 && ks->n_bytes >= (counter_type)session->opt->renegotiate_bytes)
I think we should look into making session->opt->renegotiate_bytes and ...packets an uint64_t and initialize as 0 (not -1). Saves on the cast, adds 3 more lines to the patch... not sure if the end result is really nicer, but it might worth looking at it.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1526?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I701452496bb47c58b9728b08104dd5cb7823a94f
Gerrit-Change-Number: 1526
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 31 Mar 2026 17:32:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#3 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: options: Change all users of positive_atoll to uint64_t

In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1526?usp=email

to look at the new patch set (#9).

The following approvals got outdated and were removed:
Code-Review-1 by cron2

Change subject: options: Change all users of positive_atoll to uint64_t
......................................................................

options: Change all users of positive_atoll to uint64_t

Generally this makes more sense for the usages. There is really no reason to make them signed just to have -1 as the default value. 0 works fine for that.

Avoids some existing sign-compare warnings.

Change-Id I701452496bb47c58b9728b08104dd5cb7823a94f

---
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M tests/unit_tests/openvpn/test_misc.c

10 files changed, 23 insertions(+), 32 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/26/1526/9

src/openvpn/forward.c +3 -3
index 27cfd36..e3ba0ed 100644
@@ -482,11 +482,11 @@
     if (dco_enabled(&c->options) && dco_get_peer_stats(c, true) == 0)
     {
 #ifdef TARGET_FREEBSD
-        int64_t tot_bytes = c->c2.dco_read_bytes + c->c2.dco_write_bytes;
+        counter_type tot_bytes = c->c2.dco_read_bytes + c->c2.dco_write_bytes;
 #else
-        int64_t tot_bytes = c->c2.tun_read_bytes + c->c2.tun_write_bytes;
+        counter_type tot_bytes = c->c2.tun_read_bytes + c->c2.tun_write_bytes;
 #endif
-        int64_t new_bytes = tot_bytes - c->c2.inactivity_bytes;
+        counter_type new_bytes = tot_bytes - c->c2.inactivity_bytes;
 
         if (new_bytes > c->options.inactivity_minimum_bytes)
         {
src/openvpn/forward.h +1 -1
index 0d3e492..bedad67 100644
@@ -347,7 +347,7 @@
 }
 
 static inline void
-register_activity(struct context *c, const int64_t size)
+register_activity(struct context *c, const uint64_t size)
 {
     if (c->options.inactivity_timeout)
     {
src/openvpn/openvpn.h +1 -1
index fa00822..864c160 100644
@@ -285,7 +285,7 @@
 
     /* --inactive */
     struct event_timeout inactivity_interval;
-    int64_t inactivity_bytes;
+    counter_type inactivity_bytes;
 
     struct event_timeout session_interval;
 
src/openvpn/options.c +6 -6
index 713dcf4..0d32b23 100644
@@ -864,9 +864,9 @@
     o->replay_time = DEFAULT_TIME_BACKTRACK;
     o->key_direction = KEY_DIRECTION_BIDIRECTIONAL;
     o->tls_timeout = 2;
-    o->renegotiate_bytes = -1;
+    o->renegotiate_bytes = 0;
     o->renegotiate_seconds = 3600;
-    o->renegotiate_seconds_min = -1;
+    o->renegotiate_seconds_min = 0;
     o->handshake_window = 60;
     o->transition_window = 3600;
     o->tls_cert_profile = NULL;
@@ -955,7 +955,7 @@
     SHOW_PARM(var, o->var##_inline ? "[INLINE]" : (o->var ? o->var : "[UNDEF]"), "'%s'")
 #define SHOW_INT(var)      SHOW_PARM(var, o->var, "%d")
 #define SHOW_UINT(var)     SHOW_PARM(var, o->var, "%u")
-#define SHOW_INT64(var)    SHOW_PARM(var, o->var, "%" PRIi64)
+#define SHOW_UINT64(var)   SHOW_PARM(var, o->var, "%" PRIu64)
 #define SHOW_UNSIGNED(var) SHOW_PARM(var, o->var, "0x%08x")
 #define SHOW_BOOL(var)     SHOW_PARM(var, (o->var ? "ENABLED" : "DISABLED"), "%s");
 
@@ -1715,7 +1715,7 @@
     SHOW_INT(keepalive_timeout);
     SHOW_INT(inactivity_timeout);
     SHOW_INT(session_timeout);
-    SHOW_INT64(inactivity_minimum_bytes);
+    SHOW_UINT64(inactivity_minimum_bytes);
     SHOW_INT(ping_send_timeout);
     SHOW_INT(ping_rec_timeout);
     SHOW_INT(ping_rec_timeout_action);
@@ -1892,8 +1892,8 @@
 
     SHOW_INT(tls_timeout);
 
-    SHOW_INT64(renegotiate_bytes);
-    SHOW_INT64(renegotiate_packets);
+    SHOW_UINT64(renegotiate_bytes);
+    SHOW_UINT64(renegotiate_packets);
     SHOW_INT(renegotiate_seconds);
 
     SHOW_INT(handshake_window);
src/openvpn/options.h +3 -3
index 422820c..02b1e98 100644
@@ -341,7 +341,7 @@
     int keepalive_timeout;
 
     int inactivity_timeout; /* --inactive */
-    int64_t inactivity_minimum_bytes;
+    uint64_t inactivity_minimum_bytes;
 
     int session_timeout;    /* Force-kill session after n seconds */
 
@@ -639,8 +639,8 @@
     int tls_timeout;
 
     /* Data channel key renegotiation parameters */
-    int64_t renegotiate_bytes;
-    int64_t renegotiate_packets;
+    uint64_t renegotiate_bytes;
+    uint64_t renegotiate_packets;
     int renegotiate_seconds;
     int renegotiate_seconds_min;
 
src/openvpn/options_util.c +2 -2
index 47fe0bc..6ea0c7b 100644
@@ -132,7 +132,7 @@
 }
 
 bool
-positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
+positive_atoll(const char *str, uint64_t *value, const char *name, msglvl_t msglevel)
 {
     char *endptr;
     long long ll = strtoll(str, &endptr, 10);
@@ -143,7 +143,7 @@
         return false;
     }
 
-    *value = (int64_t)ll;
+    *value = (uint64_t)ll;
     return true;
 }
 
src/openvpn/options_util.h +1 -1
index 1d4ea9b..1b007fe 100644
@@ -48,7 +48,7 @@
  *
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
-bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel);
+bool positive_atoll(const char *str, uint64_t *value, const char *name, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
src/openvpn/ssl.c +3 -12
index 576157d..cf8d644 100644
@@ -103,11 +103,11 @@
  *                      May *not* be NULL.
  */
 static void
-tls_limit_reneg_bytes(const char *ciphername, int64_t *reneg_bytes)
+tls_limit_reneg_bytes(const char *ciphername, uint64_t *reneg_bytes)
 {
     if (cipher_kt_insecure(ciphername))
     {
-        if (*reneg_bytes == -1) /* Not user-specified */
+        if (*reneg_bytes == 0) /* Not user-specified */
         {
             msg(M_WARN, "WARNING: cipher with small block size in use, "
                         "reducing reneg-bytes to 64MB to mitigate SWEET32 attacks.");
@@ -2916,11 +2916,6 @@
     return true;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 /**
  * Determines if a renegotiation should be triggerred based on the various
  * factors that can trigger one
@@ -2942,7 +2937,7 @@
     }
 
     /* Packet limit */
-    if (session->opt->renegotiate_packets && ks->n_packets >= session->opt->renegotiate_packets)
+    if (session->opt->renegotiate_packets > 0 && ks->n_packets >= session->opt->renegotiate_packets)
     {
         return true;
     }
@@ -3000,10 +2995,6 @@
     return false;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * This is the primary routine for processing TLS stuff inside the
  * the main event loop.  When this routine exits
src/openvpn/ssl_common.h +2 -2
index 6f310a5..7b35ef3 100644
@@ -342,8 +342,8 @@
     int transition_window;
     int handshake_window;
     interval_t packet_timeout;
-    int64_t renegotiate_bytes;
-    int64_t renegotiate_packets;
+    uint64_t renegotiate_bytes;
+    uint64_t renegotiate_packets;
     /** limit for AEAD cipher when not running in epoch data key mode,
      *  this is the sum of packets + blocks that are allowed to be used */
     uint64_t aead_usage_limit;
tests/unit_tests/openvpn/test_misc.c +1 -1
index a9ae33f..19303a9 100644
@@ -359,7 +359,7 @@
     assert_true(atoi_constrained("-1194", &parameter, "test", INT_MIN, INT_MAX, msglevel));
     assert_int_equal(parameter, -1194);
 
-    int64_t parameter64 = 0;
+    uint64_t parameter64 = 0;
     assert_true(positive_atoll("1234", &parameter64, "test", msglevel));
     assert_int_equal(parameter64, 1234);
     assert_true(positive_atoll("0", &parameter64, "test", msglevel));

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1526?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I701452496bb47c58b9728b08104dd5cb7823a94f
Gerrit-Change-Number: 1526
Gerrit-PatchSet: 9
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>