From 2dbee9361e74d03727a8b618ba80a5e28c006011 Mon Sep 17 00:00:00 2001 From: Jakub Grajciar Date: Fri, 7 Feb 2020 11:30:26 +0100 Subject: 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 Change-Id: Iadd59b612c0d960a34ad0dd07a9d17f56435c6ea Signed-off-by: Jakub Grajciar --- src/tools/vppapigen/vppapigen_c.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py index a893b3a89bc..46f60dea843 100644 --- a/src/tools/vppapigen/vppapigen_c.py +++ b/src/tools/vppapigen/vppapigen_c.py @@ -136,10 +136,9 @@ class Printfun(): if o.modern_vla: write(' if (vl_api_string_len(&a->{f}) > 0) {{\n' .format(f=o.fieldname)) - write(' s = format(s, "\\n%U{f}: %.*s", ' + write(' s = format(s, "\\n%U{f}: %U", ' 'format_white_space, indent, ' - 'vl_api_string_len(&a->{f}) - 1, ' - 'vl_api_from_api_string(&a->{f}));\n'.format(f=o.fieldname)) + 'vl_api_format_string, (&a->{f}));\n'.format(f=o.fieldname)) write(' } else {\n') write(' s = format(s, "\\n%U{f}:", ' 'format_white_space, indent);\n'.format(f=o.fieldname)) -- cgit 1.2.3-korg