diff options
author | 2020-02-07 11:30:26 +0100 | |
---|---|---|
committer | 2020-02-26 08:51:03 +0000 | |
commit | 2dbee9361e74d03727a8b618ba80a5e28c006011 (patch) | |
tree | 443b6c39e99e0e46b62ef0dfd002e31bb1fa7665 /src/vpp | |
parent | 8e755a16a71c55555f12381c8a12e22ae7138536 (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/vpp')
-rw-r--r-- | src/vpp/api/api.c | 13 | ||||
-rw-r--r-- | src/vpp/api/custom_dump.c | 6 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c index f652205d583..01527a565f3 100644 --- a/src/vpp/api/api.c +++ b/src/vpp/api/api.c @@ -212,7 +212,7 @@ vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp) vlib_main_t *vm = vlib_get_main (); unformat_input_t input; u8 *out_vec = 0; - u32 len = 0; + u8 *cmd_vec = 0; if (vl_msg_api_get_msg_length (mp) < vl_api_string_len (&mp->cmd) + sizeof (*mp)) @@ -221,20 +221,21 @@ vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp) goto error; } - unformat_init_string (&input, (char *) vl_api_from_api_string (&mp->cmd), + cmd_vec = vl_api_from_api_to_new_vec (&mp->cmd); + + unformat_init_string (&input, (char *) cmd_vec, vl_api_string_len (&mp->cmd)); rv = vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec); - len = vec_len (out_vec); - error: /* *INDENT-OFF* */ - REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len, + REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, vec_len (out_vec), ({ - vl_api_to_api_string(len, (const char *)out_vec, &rmp->reply); + vl_api_vec_to_api_string(out_vec, &rmp->reply); })); /* *INDENT-ON* */ vec_free (out_vec); + vec_free (cmd_vec); } static void diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c index c155039a4a6..806fee69ddb 100644 --- a/src/vpp/api/custom_dump.c +++ b/src/vpp/api/custom_dump.c @@ -1783,7 +1783,7 @@ static void *vl_api_sw_interface_dump_t_print if (mp->name_filter_valid) { - u8 *v = vl_api_from_api_to_vec (&mp->name_filter); + u8 *v = vl_api_from_api_to_new_vec (&mp->name_filter); s = format (s, "name_filter %v ", v); vec_free (v); } @@ -1841,10 +1841,8 @@ static void *vl_api_cli_inband_t_print { u8 *s; u8 *cmd = 0; - u32 length = vl_api_string_len (&mp->cmd); - vec_validate (cmd, length); - clib_memcpy (cmd, vl_api_from_api_string (&mp->cmd), length); + cmd = vl_api_from_api_to_new_vec (&mp->cmd); s = format (0, "SCRIPT: exec %v ", cmd); |