]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
buffer: Change buf_prepend and buf_advance to accept ssize_t for length
authorFrank Lichtenheld <frank@lichtenheld.com>
Mon, 15 Dec 2025 16:05:35 +0000 (17:05 +0100)
committerGert Doering <gert@greenie.muc.de>
Mon, 15 Dec 2025 16:09:22 +0000 (17:09 +0100)
We already have tests to make sure the value is sane.
Changing the argument to ssize_t allows to use it in
more places without needing to do a cast before the
checks.

Change-Id: I123002255b37160d48ef6481f68a89d03073236b
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1437
Message-Id: <20251215160541.24237-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35099.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/buffer.c
src/openvpn/buffer.h
src/openvpn/ps.c

index 40baca6f263c1716aee949f7de7ba03d47b52426..acab06b59cd219ab139668f3721a62e3761fae6e 100644 (file)
@@ -789,7 +789,7 @@ buf_string_compare_advance(struct buffer *src, const char *match)
 {
     if (buf_string_match_head_str(src, match))
     {
-        buf_advance(src, (int)strlen(match));
+        buf_advance(src, strlen(match));
         return true;
     }
     else
@@ -1312,7 +1312,7 @@ buffer_list_pop(struct buffer_list *ol)
 }
 
 void
-buffer_list_advance(struct buffer_list *ol, int n)
+buffer_list_advance(struct buffer_list *ol, ssize_t n)
 {
     if (ol->head)
     {
index 1dbe0b2b0b1adfb56d06697fc4cfbd8a24905f28..1a6358dcc538e3c0d76e7c25683800a9c97a9f82 100644 (file)
@@ -601,26 +601,26 @@ buf_inc_len(struct buffer *buf, int inc)
  */
 
 static inline uint8_t *
-buf_prepend(struct buffer *buf, int size)
+buf_prepend(struct buffer *buf, ssize_t size)
 {
     if (!buf_valid(buf) || size < 0 || size > buf->offset)
     {
         return NULL;
     }
-    buf->offset -= size;
-    buf->len += size;
+    buf->offset -= (int)size;
+    buf->len += (int)size;
     return BPTR(buf);
 }
 
 static inline bool
-buf_advance(struct buffer *buf, int size)
+buf_advance(struct buffer *buf, ssize_t size)
 {
     if (!buf_valid(buf) || size < 0 || buf->len < size)
     {
         return false;
     }
-    buf->offset += size;
-    buf->len -= size;
+    buf->offset += (int)size;
+    buf->len -= (int)size;
     return true;
 }
 
@@ -1187,7 +1187,7 @@ struct buffer_entry *buffer_list_push_data(struct buffer_list *ol, const void *d
  */
 struct buffer *buffer_list_peek(struct buffer_list *ol);
 
-void buffer_list_advance(struct buffer_list *ol, int n);
+void buffer_list_advance(struct buffer_list *ol, ssize_t n);
 
 void buffer_list_pop(struct buffer_list *ol);
 
index 31e7c2538f836c1aeec6ccc3cc4448f7b35e9ffa..917f8710f798671e34b252e61724a0b71a4416b0 100644 (file)
@@ -596,7 +596,7 @@ proxy_connection_io_send(struct proxy_connection *pc, int *bytes_sent)
         {
             dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: partial write[%d], tried=%d got=%zd", (int)sd,
                  pc->buf.len, status);
-            buf_advance(&pc->buf, (int)status);
+            buf_advance(&pc->buf, status);
             return IOSTAT_EAGAIN_ON_WRITE;
         }
         else