aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2019-12-16 16:00:14 +0100
committerDamjan Marion <dmarion@me.com>2019-12-17 17:53:43 +0000
commita7cb357491bc8adeac23a329685e8ea9aa2d2f33 (patch)
tree12384363762ca40ae8d582e292b61b2b5c924b00 /src
parent7176b800fa5570a14d9d403183131f5115158baf (diff)
vppinfra: fix cpu flag string overflow
Type: fix Change-Id: Idb1fff8a172034044bb33d5b271a84d1fd672ef5 Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/cpu.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/vppinfra/cpu.c b/src/vppinfra/cpu.c
index c1ff7dd27b3..2da87d1bb67 100644
--- a/src/vppinfra/cpu.c
+++ b/src/vppinfra/cpu.c
@@ -183,12 +183,10 @@ format_cpu_model_name (u8 * s, va_list * args)
static inline char const *
-flag_skip_prefix (char const *flag)
+flag_skip_prefix (char const *flag, const char *pfx, int len)
{
- if (memcmp (flag, "x86_", sizeof ("x86_") - 1) == 0)
- return flag + sizeof ("x86_") - 1;
- if (memcmp (flag, "aarch64_", sizeof ("aarch64_") - 1) == 0)
- return flag + sizeof ("aarch64_") - 1;
+ if (0 == strncmp (flag, pfx, len - 1))
+ return flag + len - 1;
return flag;
}
@@ -198,13 +196,13 @@ format_cpu_flags (u8 * s, va_list * args)
#if defined(__x86_64__)
#define _(flag, func, reg, bit) \
if (clib_cpu_supports_ ## flag()) \
- s = format (s, "%s ", flag_skip_prefix(#flag));
+ s = format (s, "%s ", flag_skip_prefix(#flag, "x86_", sizeof("x86_")));
foreach_x86_64_flags return s;
#undef _
#elif defined(__aarch64__)
#define _(flag, bit) \
if (clib_cpu_supports_ ## flag()) \
- s = format (s, "%s ", flag_skip_prefix(#flag));
+ s = format (s, "%s ", flag_skip_prefix(#flag, "aarch64_", sizeof("aarch64_")));
foreach_aarch64_flags return s;
#undef _
#else /* ! ! __x86_64__ && ! __aarch64__ */