aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-04-04 22:40:45 +0200
committerDamjan Marion <dmarion@me.com>2022-04-04 23:17:13 +0000
commit8bea589cfe0fca1a6f560e16ca66a4cf199041a2 (patch)
treecf2767f8f5f31344468b65e14baa3f1a4c85fb91 /src/vlibmemory
parenta2b358b1faf6e762e1d29a931d83c7735ac9a77d (diff)
vppinfra: make _vec_len() read-only
Use of _vec_len() to set vector length breaks address sanitizer. Users should use vec_set_len(), vec_inc_len(), vec_dec_len () instead. Type: improvement Change-Id: I441ae948771eb21c23a61f3ff9163bdad74a2cb8 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlibmemory')
-rw-r--r--src/vlibmemory/memclnt_api.c2
-rw-r--r--src/vlibmemory/memory_shared.c4
-rw-r--r--src/vlibmemory/socket_client.c14
-rw-r--r--src/vlibmemory/vlib_api_cli.c4
4 files changed, 12 insertions, 12 deletions
diff --git a/src/vlibmemory/memclnt_api.c b/src/vlibmemory/memclnt_api.c
index 87bb36a5426..289a4c5d947 100644
--- a/src/vlibmemory/memclnt_api.c
+++ b/src/vlibmemory/memclnt_api.c
@@ -500,7 +500,7 @@ api_rx_from_node (vlib_main_t *vm, vlib_node_runtime_t *node,
if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
{
ASSERT (long_msg != 0);
- _vec_len (long_msg) = 0;
+ vec_set_len (long_msg, 0);
vec_add (long_msg, msg, msg_len);
while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
{
diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c
index 1716f271466..5244b27ad37 100644
--- a/src/vlibmemory/memory_shared.c
+++ b/src/vlibmemory/memory_shared.c
@@ -545,8 +545,8 @@ vl_map_shmem (const char *region_name, int is_vlib)
if (strstr (region_name, vpe_api_region_suffix))
{
u8 *root_path = format (0, "%s", region_name);
- _vec_len (root_path) = (vec_len (root_path) -
- strlen (vpe_api_region_suffix));
+ vec_set_len (root_path,
+ vec_len (root_path) - strlen (vpe_api_region_suffix));
vec_terminate_c_string (root_path);
a->root_path = (const char *) root_path;
am->root_path = (const char *) root_path;
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c
index 7082d8ba7e0..237d2224d24 100644
--- a/src/vlibmemory/socket_client.c
+++ b/src/vlibmemory/socket_client.c
@@ -93,7 +93,7 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
current_rx_index = vec_len (scm->socket_rx_buffer);
vec_validate (scm->socket_rx_buffer, current_rx_index
+ scm->socket_buffer_size - 1);
- _vec_len (scm->socket_rx_buffer) = current_rx_index;
+ 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)
@@ -104,7 +104,7 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
clib_unix_warning ("socket_read");
return -1;
}
- _vec_len (scm->socket_rx_buffer) += n;
+ vec_inc_len (scm->socket_rx_buffer, n);
}
#if CLIB_DEBUG > 1
@@ -116,7 +116,7 @@ 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_len (scm->socket_rx_buffer) = current_rx_index;
+ vec_set_len (scm->socket_rx_buffer, current_rx_index);
mbp = (msgbuf_t *) (scm->socket_rx_buffer);
msg_size = data_len + sizeof (*mbp);
@@ -133,7 +133,7 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
clib_unix_warning ("socket_read");
return -1;
}
- _vec_len (scm->socket_rx_buffer) += n;
+ vec_inc_len (scm->socket_rx_buffer, n);
}
if (vec_len (scm->socket_rx_buffer) >= data_len + sizeof (*mbp))
@@ -141,7 +141,7 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait)
vl_msg_api_socket_handler ((void *) (mbp->data), data_len);
if (vec_len (scm->socket_rx_buffer) == data_len + sizeof (*mbp))
- _vec_len (scm->socket_rx_buffer) = 0;
+ vec_set_len (scm->socket_rx_buffer, 0);
else
vec_delete (scm->socket_rx_buffer, data_len + sizeof (*mbp), 0);
mbp = 0;
@@ -480,8 +480,8 @@ vl_socket_client_connect_internal (socket_client_main_t * scm,
SOCKET_CLIENT_DEFAULT_BUFFER_SIZE;
vec_validate (scm->socket_tx_buffer, scm->socket_buffer_size - 1);
vec_validate (scm->socket_rx_buffer, scm->socket_buffer_size - 1);
- _vec_len (scm->socket_rx_buffer) = 0;
- _vec_len (scm->socket_tx_buffer) = 0;
+ vec_set_len (scm->socket_rx_buffer, 0);
+ vec_set_len (scm->socket_tx_buffer, 0);
scm->name = format (0, "%s", client_name);
mp = vl_socket_client_msg_alloc2 (scm, sizeof (*mp));
diff --git a/src/vlibmemory/vlib_api_cli.c b/src/vlibmemory/vlib_api_cli.c
index e3e7ee38e10..732ced7634c 100644
--- a/src/vlibmemory/vlib_api_cli.c
+++ b/src/vlibmemory/vlib_api_cli.c
@@ -673,7 +673,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
break;
}
- _vec_len (tmpbuf) = 0;
+ vec_set_len (tmpbuf, 0);
msg += size;
}
@@ -1285,7 +1285,7 @@ extract_name (u8 * s)
rv = vec_dup (s);
while (vec_len (rv) && rv[vec_len (rv)] != '_')
- _vec_len (rv)--;
+ vec_dec_len (rv, 0);
rv[vec_len (rv)] = 0;