summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/jsonformat.c
diff options
context:
space:
mode:
authorOle Troan <otroan@employees.org>2024-08-01 14:06:24 +0200
committerBeno�t Ganne <bganne@cisco.com>2024-08-07 11:46:51 +0000
commit9aa833b144200e88a382f3583196533c95d5e68f (patch)
tree086f8a7e38570d4bcb7e87513711eb423323f917 /src/vppinfra/jsonformat.c
parentfa7b7a41e7ca9400dda2266a10dd9179be40c128 (diff)
vppapigen: ensure address types are nul terminated
A string generated from format() may not be nul terminated. Type: fix Change-Id: I88452e446c3504d70758e9009c65be5466034d92 Signed-off-by: Ole Troan <otroan@employees.org>
Diffstat (limited to 'src/vppinfra/jsonformat.c')
-rw-r--r--src/vppinfra/jsonformat.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/vppinfra/jsonformat.c b/src/vppinfra/jsonformat.c
index 1aa3864be04..73cb94769d8 100644
--- a/src/vppinfra/jsonformat.c
+++ b/src/vppinfra/jsonformat.c
@@ -500,12 +500,13 @@ format_vl_api_mac_address_t (u8 * s, va_list * args)
mac->bytes[0], mac->bytes[1], mac->bytes[2],
mac->bytes[3], mac->bytes[4], mac->bytes[5]);
}
-#define _(T) \
- cJSON *vl_api_ ##T## _t_tojson (vl_api_ ##T## _t *a) { \
- u8 *s = format(0, "%U", format_vl_api_ ##T## _t, a); \
- cJSON *o = cJSON_CreateString((char *)s); \
- vec_free(s); \
- return o; \
+#define _(T) \
+ cJSON *vl_api_##T##_t_tojson (vl_api_##T##_t *a) \
+ { \
+ char *s = format_c_string (0, "%U", format_vl_api_##T##_t, a, 0); \
+ cJSON *o = cJSON_CreateString (s); \
+ vec_free (s); \
+ return o; \
}
foreach_type_tojson
#undef _