Change in openvpn[master]: socket: Never use negative buf->len in link_socket_read*
A message that is not in the archive (sent off-list or not yet received): gerrit.1772554170000.Iabe1992b2608661b862a81363574e957d18395f0@gerrit.openvpn.net
Attention is currently required from: flichtenheld.
plaisthos has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1554?usp=email )
Change subject: socket: Never use negative buf->len in link_socket_read*
......................................................................
Patch Set 4: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1554?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: Iabe1992b2608661b862a81363574e957d18395f0
Gerrit-Change-Number: 1554
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]>
Gerrit-Comment-Date: Tue, 23 Jun 2026 09:17:12 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v4 1/1 socket: Never use negative buf->len in link_socket_read*
In reply to a message not in the archiveWe really don't want to use negative buf lengths in our code. So remove some places where we did so before.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1554
---
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/+/1554
This mail reflects revision 4 of this Change.
Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]>
src/openvpn/forward.c +4 -6
@@ -929,14 +929,12 @@* Set up for recvfrom call to read datagram * sent to our TCP/UDP port. */ -int status; -/*ASSERT (!c->c2.to_tun.len);*/ c->c2.buf = c->c2.buffers->read_link_buf;ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom)); - status =link_socket_read (sock, &c->c2.buf, &c->c2.from); +ssize_t status =link_socket_read (sock, &c->c2.buf, &c->c2.from);if (socket_connection_reset (sock, status)) {
@@ -955,14 +953,14 @@if (event_timeout_defined (&c->c2.explicit_exit_notification_interval)) {msg (D_STREAM_ERRORS , -"Connection reset during exit notification period, ignoring [%d]" , status); +"Connection reset during exit notification period, ignoring [%zd]" , status);management_sleep (1 ); }else {register_signal (c->sig,SIGUSR1 ,"connection-reset" );/* SOFT-SIGUSR1 -- TCP connection reset */ -msg (D_STREAM_ERRORS ,"Connection reset, restarting [%d]" , status); +msg (D_STREAM_ERRORS ,"Connection reset, restarting [%zd]" , status); } }return ;
@@ -1026,7 +1024,7 @@* Good, non-zero length packet received. * Commence multi-stage processing of packet, * such as authenticate, decrypt, decompress. -* If any stage fails, it sets buf.len to 0 or -1, +* If any stage fails, it sets buf.len to 0, * telling downstream stages to ignore the packet. */ if (c->c2.buf.len >0 )
src/openvpn/socket.c +71 -55
222 lines not on this page · raw message
src/openvpn/socket.h +7 -6
@@ -54,6 +54,7 @@*/ typedef uint16_t packet_size_type ; +#define PACKET_SIZE_MAX UINT16_MAX/* convert a packet_size_type from host to network order */ #define htonps (x) htons(x)
@@ -459,7 +460,7 @@#endif /* if PORT_SHARE */ static inline bool -socket_connection_reset (const struct link_socket *sock,int status) +socket_connection_reset (const struct link_socket *sock,ssize_t status) {if (link_socket_connection_oriented (sock)) {
@@ -586,7 +587,7 @@* Socket Read Routines */ -int link_socket_read_tcp (struct link_socket *sock,struct buffer *buf); +ssize_t link_socket_read_tcp (struct link_socket *sock,struct buffer *buf);#ifdef _WIN32
@@ -606,20 +607,20 @@#else /* ifdef _WIN32 */ -int link_socket_read_udp_posix (struct link_socket *sock,struct buffer *buf, -struct link_socket_actual *from); +ssize_t link_socket_read_udp_posix (struct link_socket *sock,struct buffer *buf, +struct link_socket_actual *from);#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ -static inline int +static inline ssize_t link_socket_read (struct link_socket *sock,struct buffer *buf,struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) ||socket_is_dco_win (sock))/* unified UDPv4 and UDPv6, for DCO-WIN the kernel * will strip the length header */ { -int res; +ssize_t res;#ifdef _WIN32 res =link_socket_read_udp_win32 (sock, buf, from);
src/openvpn/tun.h +2 -2
@@ -535,7 +535,7 @@ }static inline bool -tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +tuntap_is_dco_win_timeout (struct tuntap *tt,ssize_t status) {return tuntap_is_dco_win (tt) && (status <0 ) && (openvpn_errno () ==ERROR_NETNAME_DELETED ); }
@@ -573,7 +573,7 @@ }static inline bool -tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +tuntap_is_dco_win_timeout (struct tuntap *tt,ssize_t status) {return false; }
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
[Openvpn-devel] [PATCH applied] Re: socket: Never use negative buf->len in link_socket_read*
This is, if I remember correctly, "integer warning fixes fallout", but generally a good idea - so buf->len is now either "0" for "no packet" or ">0" for "do something", and errors are communicated via explicit other channels.
I did stare at this for quite a while, but since the code is complex I'm happy that Arne also did and +2ed in gerrit. Tested on the t_client/ t_server framework.
Your patch has been applied to the master branch.
commit 74c2a965d39fea89c2fe392663eb699fb1324611
Author: Frank Lichtenheld Date: Wed Jul 8 17:28:47 2026 +0200
socket: Never use negative buf->len in link_socket_read*
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1554
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37536.html
--
kind regards,
Gert Doering
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
cron2 has uploaded a new patch set (#5) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1554?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by plaisthos
Change subject: socket: Never use negative buf->len in link_socket_read*
......................................................................
socket: Never use negative buf->len in link_socket_read*
We really don't want to use negative buf lengths in our code. So remove some places where we did so before.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1554
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37536.html
---
M src/openvpn/forward.c
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.h
4 files changed, 84 insertions(+), 69 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/54/1554/5
src/openvpn/forward.c +4 -6
@@ -929,14 +929,12 @@* Set up for recvfrom call to read datagram * sent to our TCP/UDP port. */ -int status; -/*ASSERT (!c->c2.to_tun.len);*/ c->c2.buf = c->c2.buffers->read_link_buf;ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom)); - status =link_socket_read (sock, &c->c2.buf, &c->c2.from); +ssize_t status =link_socket_read (sock, &c->c2.buf, &c->c2.from);if (socket_connection_reset (sock, status)) {
@@ -955,14 +953,14 @@if (event_timeout_defined (&c->c2.explicit_exit_notification_interval)) {msg (D_STREAM_ERRORS , -"Connection reset during exit notification period, ignoring [%d]" , status); +"Connection reset during exit notification period, ignoring [%zd]" , status);management_sleep (1 ); }else {register_signal (c->sig,SIGUSR1 ,"connection-reset" );/* SOFT-SIGUSR1 -- TCP connection reset */ -msg (D_STREAM_ERRORS ,"Connection reset, restarting [%d]" , status); +msg (D_STREAM_ERRORS ,"Connection reset, restarting [%zd]" , status); } }return ;
@@ -1026,7 +1024,7 @@* Good, non-zero length packet received. * Commence multi-stage processing of packet, * such as authenticate, decrypt, decompress. -* If any stage fails, it sets buf.len to 0 or -1, +* If any stage fails, it sets buf.len to 0, * telling downstream stages to ignore the packet. */ if (c->c2.buf.len >0 )
src/openvpn/socket.c +71 -55
222 lines not on this page · raw message
src/openvpn/socket.h +7 -6
@@ -54,6 +54,7 @@*/ typedef uint16_t packet_size_type ; +#define PACKET_SIZE_MAX UINT16_MAX/* convert a packet_size_type from host to network order */ #define htonps (x) htons(x)
@@ -457,7 +458,7 @@#endif /* if PORT_SHARE */ static inline bool -socket_connection_reset (const struct link_socket *sock,int status) +socket_connection_reset (const struct link_socket *sock,ssize_t status) {if (link_socket_connection_oriented (sock)) {
@@ -584,7 +585,7 @@* Socket Read Routines */ -int link_socket_read_tcp (struct link_socket *sock,struct buffer *buf); +ssize_t link_socket_read_tcp (struct link_socket *sock,struct buffer *buf);#ifdef _WIN32
@@ -604,20 +605,20 @@#else /* ifdef _WIN32 */ -int link_socket_read_udp_posix (struct link_socket *sock,struct buffer *buf, -struct link_socket_actual *from); +ssize_t link_socket_read_udp_posix (struct link_socket *sock,struct buffer *buf, +struct link_socket_actual *from);#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ -static inline int +static inline ssize_t link_socket_read (struct link_socket *sock,struct buffer *buf,struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) ||socket_is_dco_win (sock))/* unified UDPv4 and UDPv6, for DCO-WIN the kernel * will strip the length header */ { -int res; +ssize_t res;#ifdef _WIN32 res =link_socket_read_udp_win32 (sock, buf, from);
src/openvpn/tun.h +2 -2
@@ -535,7 +535,7 @@ }static inline bool -tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +tuntap_is_dco_win_timeout (struct tuntap *tt,ssize_t status) {return tuntap_is_dco_win (tt) && (status <0 ) && (openvpn_errno () ==ERROR_NETNAME_DELETED ); }
@@ -573,7 +573,7 @@ }static inline bool -tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +tuntap_is_dco_win_timeout (struct tuntap *tt,ssize_t status) {return false; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1554?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: Iabe1992b2608661b862a81363574e957d18395f0
Gerrit-Change-Number: 1554
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1554?usp=email )
Change subject: socket: Never use negative buf->len in link_socket_read*
......................................................................
socket: Never use negative buf->len in link_socket_read*
We really don't want to use negative buf lengths in our code. So remove some places where we did so before.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1554
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37536.html
---
M src/openvpn/forward.c
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.h
4 files changed, 84 insertions(+), 69 deletions(-)
src/openvpn/forward.c +4 -6
@@ -929,14 +929,12 @@* Set up for recvfrom call to read datagram * sent to our TCP/UDP port. */ -int status; -/*ASSERT (!c->c2.to_tun.len);*/ c->c2.buf = c->c2.buffers->read_link_buf;ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom)); - status =link_socket_read (sock, &c->c2.buf, &c->c2.from); +ssize_t status =link_socket_read (sock, &c->c2.buf, &c->c2.from);if (socket_connection_reset (sock, status)) {
@@ -955,14 +953,14 @@if (event_timeout_defined (&c->c2.explicit_exit_notification_interval)) {msg (D_STREAM_ERRORS , -"Connection reset during exit notification period, ignoring [%d]" , status); +"Connection reset during exit notification period, ignoring [%zd]" , status);management_sleep (1 ); }else {register_signal (c->sig,SIGUSR1 ,"connection-reset" );/* SOFT-SIGUSR1 -- TCP connection reset */ -msg (D_STREAM_ERRORS ,"Connection reset, restarting [%d]" , status); +msg (D_STREAM_ERRORS ,"Connection reset, restarting [%zd]" , status); } }return ;
@@ -1026,7 +1024,7 @@* Good, non-zero length packet received. * Commence multi-stage processing of packet, * such as authenticate, decrypt, decompress. -* If any stage fails, it sets buf.len to 0 or -1, +* If any stage fails, it sets buf.len to 0, * telling downstream stages to ignore the packet. */ if (c->c2.buf.len >0 )
src/openvpn/socket.c +71 -55
222 lines not on this page · raw message
src/openvpn/socket.h +7 -6
@@ -54,6 +54,7 @@*/ typedef uint16_t packet_size_type ; +#define PACKET_SIZE_MAX UINT16_MAX/* convert a packet_size_type from host to network order */ #define htonps (x) htons(x)
@@ -457,7 +458,7 @@#endif /* if PORT_SHARE */ static inline bool -socket_connection_reset (const struct link_socket *sock,int status) +socket_connection_reset (const struct link_socket *sock,ssize_t status) {if (link_socket_connection_oriented (sock)) {
@@ -584,7 +585,7 @@* Socket Read Routines */ -int link_socket_read_tcp (struct link_socket *sock,struct buffer *buf); +ssize_t link_socket_read_tcp (struct link_socket *sock,struct buffer *buf);#ifdef _WIN32
@@ -604,20 +605,20 @@#else /* ifdef _WIN32 */ -int link_socket_read_udp_posix (struct link_socket *sock,struct buffer *buf, -struct link_socket_actual *from); +ssize_t link_socket_read_udp_posix (struct link_socket *sock,struct buffer *buf, +struct link_socket_actual *from);#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ -static inline int +static inline ssize_t link_socket_read (struct link_socket *sock,struct buffer *buf,struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) ||socket_is_dco_win (sock))/* unified UDPv4 and UDPv6, for DCO-WIN the kernel * will strip the length header */ { -int res; +ssize_t res;#ifdef _WIN32 res =link_socket_read_udp_win32 (sock, buf, from);
src/openvpn/tun.h +2 -2
@@ -535,7 +535,7 @@ }static inline bool -tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +tuntap_is_dco_win_timeout (struct tuntap *tt,ssize_t status) {return tuntap_is_dco_win (tt) && (status <0 ) && (openvpn_errno () ==ERROR_NETNAME_DELETED ); }
@@ -573,7 +573,7 @@ }static inline bool -tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +tuntap_is_dco_win_timeout (struct tuntap *tt,ssize_t status) {return false; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1554?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: Iabe1992b2608661b862a81363574e957d18395f0
Gerrit-Change-Number: 1554
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel