Skip to contentSkip to conversation

Change in openvpn[master]: socket: Avoid sign-compare issue by comparing before assignment

Openvpn-devel In review flichtenheld (Code Review) 2 participants 7 messages Feb 13 – Mar 12 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.Idf5ce8f82e7727505cce67560e0b7423b8e41a40@...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/+/1523?usp=email

to review the following change.

Change subject: socket: Avoid sign-compare issue by comparing before assignment
......................................................................

socket: Avoid sign-compare issue by comparing before assignment

The assignment implicitly converts the values, but we can just do the comparison before the assignment.

Change-Id Idf5ce8f82e7727505cce67560e0b7423b8e41a40

---
M src/openvpn/socket.c

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

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/1523/1

src/openvpn/socket.c +2 -12
index 698e724..13322f5 100644
@@ -2523,11 +2523,6 @@
     return WSAGetLastError();
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 int
 socket_recv_queue(struct link_socket *sock, int maxsize)
 {
@@ -2552,11 +2547,10 @@
 
         /* Win32 docs say it's okay to allocate the wsabuf on the stack */
         wsabuf[0].buf = BSTR(&sock->reads.buf);
+        /* make sure maxsize is sane */
+        ASSERT(maxsize <= BLEN(&sock->reads.buf));
         wsabuf[0].len = maxsize ? maxsize : BLEN(&sock->reads.buf);
 
-        /* check for buffer overflow */
-        ASSERT(wsabuf[0].len <= BLEN(&sock->reads.buf));
-
         /* the overlapped read will signal this event on I/O completion */
         ASSERT(ResetEvent(sock->reads.overlapped.hEvent));
         sock->reads.flags = 0;
@@ -2629,10 +2623,6 @@
     return sock->reads.iostate;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 int
 socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1523?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: Idf5ce8f82e7727505cce67560e0b7423b8e41a40
Gerrit-Change-Number: 1523
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/+/1523?usp=email )

Change subject: socket: Avoid sign-compare issue by comparing before assignment
......................................................................

Patch Set 3: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1523?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: Idf5ce8f82e7727505cce67560e0b7423b8e41a40
Gerrit-Change-Number: 1523
Gerrit-PatchSet: 3
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: Fri, 06 Mar 2026 16:31:50 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#3 lore raw

PATCH v3 1/1 socket: Avoid sign-compare issue by comparing before assignment

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

The assignment implicitly converts the values, but we can just do the comparison before the assignment.

Change-Id Idf5ce8f82e7727505cce67560e0b7423b8e41a40

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1523
---

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

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/socket.c +2 -12
index 8d2d110..5df0792 100644
@@ -2550,11 +2550,6 @@
     return WSAGetLastError();
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 int
 socket_recv_queue(struct link_socket *sock, int maxsize)
 {
@@ -2579,11 +2574,10 @@
 
         /* Win32 docs say it's okay to allocate the wsabuf on the stack */
         wsabuf[0].buf = BSTR(&sock->reads.buf);
+        /* make sure maxsize is sane */
+        ASSERT(maxsize <= BLEN(&sock->reads.buf));
         wsabuf[0].len = maxsize ? maxsize : BLEN(&sock->reads.buf);
 
-        /* check for buffer overflow */
-        ASSERT(wsabuf[0].len <= BLEN(&sock->reads.buf));
-
         /* the overlapped read will signal this event on I/O completion */
         ASSERT(ResetEvent(sock->reads.overlapped.hEvent));
         sock->reads.flags = 0;
@@ -2656,10 +2650,6 @@
     return sock->reads.iostate;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 int
 socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
 {
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: socket: Avoid sign-compare issue by comparing before assignment

Patch looks good. Easy enough. BB green :-)

(Note: there is a v4 in gerrit now, and the ACK applied to v3 - but the actual patch is identical, it just was rebased in the meantime since the +2 was sent a while ago)

Your patch has been applied to the master branch.

commit 45f52d3aef2c014127e9a9d19368ee6c0547c1a2

Author: Frank Lichtenheld
Date:   Fri Mar 6 17:31:56 2026 +0100
     socket: Avoid sign-compare issue by comparing before assignment

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1523
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg35961.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

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

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

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

The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.

Change subject: socket: Avoid sign-compare issue by comparing before assignment
......................................................................

socket: Avoid sign-compare issue by comparing before assignment

The assignment implicitly converts the values, but we can just do the comparison before the assignment.

Change-Id Idf5ce8f82e7727505cce67560e0b7423b8e41a40

---
M src/openvpn/socket.c

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

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/1523/4

src/openvpn/socket.c +2 -12
index 8d2d110..5df0792 100644
@@ -2550,11 +2550,6 @@
     return WSAGetLastError();
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 int
 socket_recv_queue(struct link_socket *sock, int maxsize)
 {
@@ -2579,11 +2574,10 @@
 
         /* Win32 docs say it's okay to allocate the wsabuf on the stack */
         wsabuf[0].buf = BSTR(&sock->reads.buf);
+        /* make sure maxsize is sane */
+        ASSERT(maxsize <= BLEN(&sock->reads.buf));
         wsabuf[0].len = maxsize ? maxsize : BLEN(&sock->reads.buf);
 
-        /* check for buffer overflow */
-        ASSERT(wsabuf[0].len <= BLEN(&sock->reads.buf));
-
         /* the overlapped read will signal this event on I/O completion */
         ASSERT(ResetEvent(sock->reads.overlapped.hEvent));
         sock->reads.flags = 0;
@@ -2656,10 +2650,6 @@
     return sock->reads.iostate;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 int
 socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1523?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: Idf5ce8f82e7727505cce67560e0b7423b8e41a40
Gerrit-Change-Number: 1523
Gerrit-PatchSet: 4
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]...>

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

cron2 has uploaded a new patch set (#5) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1523?usp=email )

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

Change subject: socket: Avoid sign-compare issue by comparing before assignment
......................................................................

socket: Avoid sign-compare issue by comparing before assignment

The assignment implicitly converts the values, but we can just do the comparison before the assignment.

Change-Id Idf5ce8f82e7727505cce67560e0b7423b8e41a40

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1523
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35961.html

---
M src/openvpn/socket.c

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

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/1523/5

src/openvpn/socket.c +2 -12
index 8d2d110..5df0792 100644
@@ -2550,11 +2550,6 @@
     return WSAGetLastError();
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 int
 socket_recv_queue(struct link_socket *sock, int maxsize)
 {
@@ -2579,11 +2574,10 @@
 
         /* Win32 docs say it's okay to allocate the wsabuf on the stack */
         wsabuf[0].buf = BSTR(&sock->reads.buf);
+        /* make sure maxsize is sane */
+        ASSERT(maxsize <= BLEN(&sock->reads.buf));
         wsabuf[0].len = maxsize ? maxsize : BLEN(&sock->reads.buf);
 
-        /* check for buffer overflow */
-        ASSERT(wsabuf[0].len <= BLEN(&sock->reads.buf));
-
         /* the overlapped read will signal this event on I/O completion */
         ASSERT(ResetEvent(sock->reads.overlapped.hEvent));
         sock->reads.flags = 0;
@@ -2656,10 +2650,6 @@
     return sock->reads.iostate;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 int
 socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1523?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: Idf5ce8f82e7727505cce67560e0b7423b8e41a40
Gerrit-Change-Number: 1523
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

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

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1523?usp=email )

Change subject: socket: Avoid sign-compare issue by comparing before assignment
......................................................................

socket: Avoid sign-compare issue by comparing before assignment

The assignment implicitly converts the values, but we can just do the comparison before the assignment.

Change-Id Idf5ce8f82e7727505cce67560e0b7423b8e41a40

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1523
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35961.html

---
M src/openvpn/socket.c

1 file changed, 2 insertions(+), 12 deletions(-)
src/openvpn/socket.c +2 -12
index 8d2d110..5df0792 100644
@@ -2550,11 +2550,6 @@
     return WSAGetLastError();
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 int
 socket_recv_queue(struct link_socket *sock, int maxsize)
 {
@@ -2579,11 +2574,10 @@
 
         /* Win32 docs say it's okay to allocate the wsabuf on the stack */
         wsabuf[0].buf = BSTR(&sock->reads.buf);
+        /* make sure maxsize is sane */
+        ASSERT(maxsize <= BLEN(&sock->reads.buf));
         wsabuf[0].len = maxsize ? maxsize : BLEN(&sock->reads.buf);
 
-        /* check for buffer overflow */
-        ASSERT(wsabuf[0].len <= BLEN(&sock->reads.buf));
-
         /* the overlapped read will signal this event on I/O completion */
         ASSERT(ResetEvent(sock->reads.overlapped.hEvent));
         sock->reads.flags = 0;
@@ -2656,10 +2650,6 @@
     return sock->reads.iostate;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 int
 socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
 {

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

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Idf5ce8f82e7727505cce67560e0b7423b8e41a40
Gerrit-Change-Number: 1523
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>