From: Frank Lichtenheld Date: Mon, 15 Dec 2025 16:05:35 +0000 (+0100) Subject: buffer: Change buf_prepend and buf_advance to accept ssize_t for length X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb4d5426d0751ce4720fbc7531de51731725a5fb;p=thirdparty%2Fopenvpn.git buffer: Change buf_prepend and buf_advance to accept ssize_t for length 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 Acked-by: Gert Doering 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 --- diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 40baca6f2..acab06b59 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -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) { diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 1dbe0b2b0..1a6358dcc 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -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); diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c index 31e7c2538..917f8710f 100644 --- a/src/openvpn/ps.c +++ b/src/openvpn/ps.c @@ -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