aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2020-02-07 11:30:26 +0100
committerOle Trøan <otroan@employees.org>2020-02-26 08:51:03 +0000
commit2dbee9361e74d03727a8b618ba80a5e28c006011 (patch)
tree443b6c39e99e0e46b62ef0dfd002e31bb1fa7665 /src/vnet
parent8e755a16a71c55555f12381c8a12e22ae7138536 (diff)
api: improve api string safety
- Remove vl_api_from_api_string to prevent use of not nul-terminated strings. - Rename vl_api_from_api_to_vec -> vl_api_from_api_to_new_vec to imply a new vector is created. NOT nul terminated. - Add vl_api_from_api_to_new_c_string. Returns nul terminated string in a new vector. - Add vl_api_c_string_to_api_string. Convert nul terminated string to vl_api_string_t - Add vl_api_vec_to_api_string. Convert NON nul terminated vector to vl_api_string_t Type: fix Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: Iadd59b612c0d960a34ad0dd07a9d17f56435c6ea Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/devices/tap/tapv2_api.c2
-rw-r--r--src/vnet/interface_api.c2
-rw-r--r--src/vnet/ip/punt_api.c4
3 files changed, 4 insertions, 4 deletions
diff --git a/src/vnet/devices/tap/tapv2_api.c b/src/vnet/devices/tap/tapv2_api.c
index e0121a83c2f..3b66bf0d6ec 100644
--- a/src/vnet/devices/tap/tapv2_api.c
+++ b/src/vnet/devices/tap/tapv2_api.c
@@ -134,7 +134,7 @@ vl_api_tap_create_v2_t_handler (vl_api_tap_create_v2_t * mp)
/* If a tag was supplied... */
if (vl_api_string_len (&mp->tag))
{
- u8 *tag = format (0, "%s%c", vl_api_from_api_string (&mp->tag), 0);
+ u8 *tag = vl_api_from_api_to_new_vec (&mp->tag);
vnet_set_sw_interface_tag (vnm, tag, ap->sw_if_index);
}
diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c
index fe3426cb827..7086c5c4c7b 100644
--- a/src/vnet/interface_api.c
+++ b/src/vnet/interface_api.c
@@ -358,7 +358,7 @@ vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
if (mp->name_filter_valid)
{
- filter = vl_api_from_api_to_vec (&mp->name_filter);
+ filter = vl_api_from_api_to_new_vec (&mp->name_filter);
vec_add1 (filter, 0); /* Ensure it's a C string for strcasecmp() */
}
diff --git a/src/vnet/ip/punt_api.c b/src/vnet/ip/punt_api.c
index 6ed62a1873c..077b1ac3a69 100644
--- a/src/vnet/ip/punt_api.c
+++ b/src/vnet/ip/punt_api.c
@@ -347,7 +347,7 @@ punt_reason_dump_walk_cb (vlib_punt_reason_t id, const u8 * name, void *args)
mp->context = ctx->context;
mp->reason.id = clib_host_to_net_u32 (id);
- vl_api_to_api_string (vec_len (name), (char *) name, &mp->reason.name);
+ vl_api_vec_to_api_string (name, &mp->reason.name);
vl_api_send_msg (ctx->reg, (u8 *) mp);
@@ -366,7 +366,7 @@ vl_api_punt_reason_dump_t_handler (vl_api_punt_reason_dump_t * mp)
punt_reason_dump_walk_ctx_t ctx = {
.reg = reg,
.context = mp->context,
- .name = vl_api_from_api_to_vec (&mp->reason.name),
+ .name = vl_api_from_api_to_new_vec (&mp->reason.name),
};
punt_reason_walk (punt_reason_dump_walk_cb, &ctx);