summaryrefslogtreecommitdiffstats
path: root/src/vat
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/vat
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/vat')
-rw-r--r--src/vat/api_format.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index acb173042db..f85e94a50b7 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -1127,18 +1127,12 @@ vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
{
vat_main_t *vam = &vat_main;
i32 retval = ntohl (mp->retval);
- u32 length = vl_api_string_len (&mp->reply);
vec_reset_length (vam->cmd_reply);
vam->retval = retval;
if (retval == 0)
- {
- vec_validate (vam->cmd_reply, length);
- clib_memcpy ((char *) (vam->cmd_reply),
- vl_api_from_api_string (&mp->reply), length);
- vam->cmd_reply[length] = 0;
- }
+ vam->cmd_reply = vl_api_from_api_to_new_vec (&mp->reply);
vam->result_ready = 1;
}
@@ -1147,16 +1141,18 @@ vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
{
vat_main_t *vam = &vat_main;
vat_json_node_t node;
+ u8 *reply = 0; /* reply vector */
+ reply = vl_api_from_api_to_new_vec (&mp->reply);
vec_reset_length (vam->cmd_reply);
vat_json_init_object (&node);
vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_string_copy (&node, "reply",
- vl_api_from_api_string (&mp->reply));
+ vat_json_object_add_string_copy (&node, "reply", reply);
vat_json_print (vam->ofp, &node);
vat_json_free (&node);
+ vec_free (reply);
vam->retval = ntohl (mp->retval);
vam->result_ready = 1;
@@ -5638,9 +5634,8 @@ exec_inband (vat_main_t * vam)
* must be a vector ending in \n, not a C-string ending
* in \n\0.
*/
- u32 len = vec_len (vam->input->buffer);
- M2 (CLI_INBAND, mp, len);
- vl_api_to_api_string (len - 1, (const char *) vam->input->buffer, &mp->cmd);
+ M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
+ vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
S (mp);
W (ret);