summaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/socket_client.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2023-01-26 19:28:16 +0100
committerFlorin Coras <florin.coras@gmail.com>2023-01-27 16:38:28 +0000
commita769a508f4f3bb61b372c1382cbcfc531a884d31 (patch)
treefd84ad33d703c10a03f9c239eb67f0111eb66361 /src/vlibmemory/socket_client.c
parent8a1d07922b20f0c960af4b99c642aec08ae1b9c4 (diff)
api: keep AddressSanitizer happy
Playing with vector length prevents AddressSanitizer to track accessible memory. Make sure we update the size of the vector once we received the data. Type: fix Change-Id: If7808254d46d7ab37d516e3de49e3583d07bb9ff Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vlibmemory/socket_client.c')
-rw-r--r--src/vlibmemory/socket_client.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c
index bf6861b1ea9..5fa19c6a9c0 100644
--- a/src/vlibmemory/socket_client.c
+++ b/src/vlibmemory/socket_client.c
@@ -87,12 +87,11 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
while (1)
{
- while (vec_len (scm->socket_rx_buffer) < sizeof (*mbp))
+ current_rx_index = vec_len (scm->socket_rx_buffer);
+ while (current_rx_index < sizeof (*mbp))
{
- current_rx_index = vec_len (scm->socket_rx_buffer);
vec_validate (scm->socket_rx_buffer, current_rx_index
+ scm->socket_buffer_size - 1);
- vec_set_len (scm->socket_rx_buffer, current_rx_index);
n = read (scm->socket_fd, scm->socket_rx_buffer + current_rx_index,
scm->socket_buffer_size);
if (n < 0)
@@ -101,10 +100,12 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
continue;
clib_unix_warning ("socket_read");
+ vec_set_len (scm->socket_rx_buffer, current_rx_index);
return -1;
}
- vec_inc_len (scm->socket_rx_buffer, n);
+ current_rx_index += n;
}
+ vec_set_len (scm->socket_rx_buffer, current_rx_index);
#if CLIB_DEBUG > 1
if (n > 0)
@@ -115,25 +116,25 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
data_len = ntohl (mbp->data_len);
current_rx_index = vec_len (scm->socket_rx_buffer);
vec_validate (scm->socket_rx_buffer, current_rx_index + data_len);
- vec_set_len (scm->socket_rx_buffer, current_rx_index);
mbp = (msgbuf_t *) (scm->socket_rx_buffer);
msg_size = data_len + sizeof (*mbp);
- while (vec_len (scm->socket_rx_buffer) < msg_size)
+ while (current_rx_index < msg_size)
{
- n = read (scm->socket_fd,
- scm->socket_rx_buffer + vec_len (scm->socket_rx_buffer),
- msg_size - vec_len (scm->socket_rx_buffer));
+ n = read (scm->socket_fd, scm->socket_rx_buffer + current_rx_index,
+ msg_size - current_rx_index);
if (n < 0)
{
if (errno == EAGAIN)
continue;
clib_unix_warning ("socket_read");
+ vec_set_len (scm->socket_rx_buffer, current_rx_index);
return -1;
}
- vec_inc_len (scm->socket_rx_buffer, n);
+ current_rx_index += n;
}
+ vec_set_len (scm->socket_rx_buffer, current_rx_index);
if (vec_len (scm->socket_rx_buffer) >= data_len + sizeof (*mbp))
{