summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/test/compress.c
diff options
context:
space:
mode:
authorDmitry Valter <d-valter@yandex-team.com>2024-03-06 22:43:27 +0000
committerDamjan Marion <dmarion@0xa5.net>2024-04-08 11:46:30 +0000
commit3150250bc911b669b80dd4fe11c099430ceab172 (patch)
tree0c5a8059c3ad99b1fbf5f55c6c6cd83343953615 /src/vppinfra/test/compress.c
parentdf47a0812ab9365b2de10a7aabcf4b29a255c088 (diff)
vppinfra: fix mask compare and compress OOB reads
Use mask_load_zero to avoid out-of-buffer reads in vectorized function versions. Type: fix Signed-off-by: Dmitry Valter <d-valter@yandex-team.com> Change-Id: I12bcb817ccf2db210c1c99fdfa444dc3f540035b
Diffstat (limited to 'src/vppinfra/test/compress.c')
-rw-r--r--src/vppinfra/test/compress.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/vppinfra/test/compress.c b/src/vppinfra/test/compress.c
index 7b97f4c31af..083065f9bda 100644
--- a/src/vppinfra/test/compress.c
+++ b/src/vppinfra/test/compress.c
@@ -51,18 +51,21 @@ static compress_test_t tests[] = {
static clib_error_t *
test_clib_compress_u64 (clib_error_t *err)
{
- u64 src[513];
- u64 dst[513];
u32 i, j;
- for (i = 0; i < ARRAY_LEN (src); i++)
- src[i] = i;
-
for (i = 0; i < ARRAY_LEN (tests); i++)
{
compress_test_t *t = tests + i;
+ u64 src[t->n_elts];
+#ifdef CLIB_SANITIZE_ADDR
+ u64 dst[t->n_elts];
+#else /* CLIB_SANITIZE_ADDR */
+ u64 dst[513];
+#endif /* CLIB_SANITIZE_ADDR */
u64 *dp = dst;
u32 r;
+ for (j = 0; j < t->n_elts; j++)
+ src[j] = j;
for (j = 0; j < ARRAY_LEN (dst); j++)
dst[j] = 0xa5a5a5a5a5a5a5a5;
@@ -81,8 +84,10 @@ test_clib_compress_u64 (clib_error_t *err)
dp++;
}
+#ifndef CLIB_SANITIZE_ADDR
if (dst[dp - dst + 1] != 0xa5a5a5a5a5a5a5a5)
return clib_error_return (err, "buffer overrun in testcase %u", i);
+#endif /* CLIB_SANITIZE_ADDR */
if (dp - dst != r)
return clib_error_return (err, "wrong number of elts in testcase %u",
@@ -95,18 +100,21 @@ test_clib_compress_u64 (clib_error_t *err)
static clib_error_t *
test_clib_compress_u32 (clib_error_t *err)
{
- u32 src[513];
- u32 dst[513];
u32 i, j;
- for (i = 0; i < ARRAY_LEN (src); i++)
- src[i] = i;
-
for (i = 0; i < ARRAY_LEN (tests); i++)
{
compress_test_t *t = tests + i;
+ u32 src[t->n_elts];
+#ifdef CLIB_SANITIZE_ADDR
+ u32 dst[t->n_elts];
+#else /* CLIB_SANITIZE_ADDR */
+ u32 dst[513];
+#endif /* CLIB_SANITIZE_ADDR */
u32 *dp = dst;
u32 r;
+ for (j = 0; j < t->n_elts; j++)
+ src[j] = j;
for (j = 0; j < ARRAY_LEN (dst); j++)
dst[j] = 0xa5a5a5a5;
@@ -126,8 +134,10 @@ test_clib_compress_u32 (clib_error_t *err)
dp++;
}
+#ifndef CLIB_SANITIZE_ADDR
if (dst[dp - dst + 1] != 0xa5a5a5a5)
return clib_error_return (err, "buffer overrun in testcase %u", i);
+#endif /* CLIB_SANITIZE_ADDR */
if (dp - dst != r)
return clib_error_return (err, "wrong number of elts in testcase %u",
@@ -140,18 +150,21 @@ test_clib_compress_u32 (clib_error_t *err)
static clib_error_t *
test_clib_compress_u16 (clib_error_t *err)
{
- u16 src[513];
- u16 dst[513];
u32 i, j;
- for (i = 0; i < ARRAY_LEN (src); i++)
- src[i] = i;
-
for (i = 0; i < ARRAY_LEN (tests); i++)
{
compress_test_t *t = tests + i;
+ u16 src[t->n_elts];
+#ifdef CLIB_SANITIZE_ADDR
+ u16 dst[t->n_elts];
+#else /* CLIB_SANITIZE_ADDR */
+ u16 dst[513];
+#endif /* CLIB_SANITIZE_ADDR */
u16 *dp = dst;
u32 r;
+ for (j = 0; j < t->n_elts; j++)
+ src[j] = j;
for (j = 0; j < ARRAY_LEN (dst); j++)
dst[j] = 0xa5a5;
@@ -170,8 +183,10 @@ test_clib_compress_u16 (clib_error_t *err)
dp++;
}
+#ifndef CLIB_SANITIZE_ADDR
if (dst[dp - dst + 1] != 0xa5a5)
return clib_error_return (err, "buffer overrun in testcase %u", i);
+#endif /* CLIB_SANITIZE_ADDR */
if (dp - dst != r)
return clib_error_return (err, "wrong number of elts in testcase %u",
@@ -184,18 +199,21 @@ test_clib_compress_u16 (clib_error_t *err)
static clib_error_t *
test_clib_compress_u8 (clib_error_t *err)
{
- u8 src[513];
- u8 dst[513];
u32 i, j;
- for (i = 0; i < ARRAY_LEN (src); i++)
- src[i] = i;
-
for (i = 0; i < ARRAY_LEN (tests); i++)
{
compress_test_t *t = tests + i;
+ u8 src[t->n_elts];
+#ifdef CLIB_SANITIZE_ADDR
+ u8 dst[t->n_elts];
+#else /* CLIB_SANITIZE_ADDR */
+ u8 dst[513];
+#endif /* CLIB_SANITIZE_ADDR */
u8 *dp = dst;
u32 r;
+ for (j = 0; j < t->n_elts; j++)
+ src[j] = j;
for (j = 0; j < ARRAY_LEN (dst); j++)
dst[j] = 0xa5;
@@ -214,8 +232,10 @@ test_clib_compress_u8 (clib_error_t *err)
dp++;
}
+#ifndef CLIB_SANITIZE_ADDR
if (dst[dp - dst + 1] != 0xa5)
return clib_error_return (err, "buffer overrun in testcase %u", i);
+#endif /* CLIB_SANITIZE_ADDR */
if (dp - dst != r)
return clib_error_return (err, "wrong number of elts in testcase %u",