aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/memclnt_api.c
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-11-22 21:26:20 +0100
committerOle Tr�an <otroan@employees.org>2021-12-14 09:15:48 +0000
commit9b7e8acf792cced80e6775bc5668d9db415cdb46 (patch)
treeb600764a60f9978017a567390a025d2777b864a1 /src/vlibmemory/memclnt_api.c
parent755042dec0fcc733d456adc2a74042c529eff039 (diff)
api: verify message size on receipt
When a message is received, verify that it's sufficiently large to accomodate any VLAs within message. To do that, we need a way to calculate message size including any VLAs. This patch adds such funcionality to vppapigen and necessary C code to use those to validate message size on receipt. Drop messages which are malformed. Type: improvement Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I2903aa21dee84be6822b064795ba314de46c18f4
Diffstat (limited to 'src/vlibmemory/memclnt_api.c')
-rw-r--r--src/vlibmemory/memclnt_api.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/vlibmemory/memclnt_api.c b/src/vlibmemory/memclnt_api.c
index 2b4a2393db3..87bb36a5426 100644
--- a/src/vlibmemory/memclnt_api.c
+++ b/src/vlibmemory/memclnt_api.c
@@ -58,6 +58,10 @@
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_endianfun
+#define vl_calcsizefun
+#include <vlibmemory/vl_memory_api_h.h>
+#undef vl_calcsizefun
+
static void
vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t *mp)
{
@@ -177,6 +181,7 @@ vlib_api_init (void)
c->print_json = vl_api_##n##_t_print_json; \
c->tojson = vl_api_##n##_t_tojson; \
c->fromjson = vl_api_##n##_t_fromjson; \
+ c->calc_size = vl_api_##n##_t_calc_size; \
c->size = sizeof (vl_api_##n##_t); \
c->traced = 1; /* trace, so these msgs print */ \
c->replay = 0; /* don't replay client create/delete msgs */ \
@@ -505,8 +510,9 @@ api_rx_from_node (vlib_main_t *vm, vlib_node_runtime_t *node,
vec_add (long_msg, msg, msg_len);
}
msg = long_msg;
+ msg_len = vec_len (long_msg);
}
- vl_msg_api_handler_no_trace_no_free (msg);
+ vl_msg_api_handler_no_trace_no_free (msg, msg_len);
}
/* Free what we've been given. */
@@ -704,20 +710,20 @@ rpc_api_hookup (vlib_main_t *vm)
{
api_main_t *am = vlibapi_get_main ();
#define _(N, n) \
- vl_msg_api_set_handlers (VL_API_##N, #n, vl_api_##n##_t_handler, \
- vl_noop_handler, vl_noop_handler, \
- vl_api_##n##_t_print, sizeof (vl_api_##n##_t), \
- 0 /* do not trace */, vl_api_##n##_t_print_json, \
- vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson);
+ vl_msg_api_set_handlers ( \
+ VL_API_##N, #n, vl_api_##n##_t_handler, vl_noop_handler, vl_noop_handler, \
+ vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 0 /* do not trace */, \
+ vl_api_##n##_t_print_json, vl_api_##n##_t_tojson, \
+ vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
foreach_rpc_api_msg;
#undef _
#define _(N, n) \
- vl_msg_api_set_handlers (VL_API_##N, #n, vl_api_##n##_t_handler, \
- vl_noop_handler, vl_noop_handler, \
- vl_api_##n##_t_print, sizeof (vl_api_##n##_t), \
- 1 /* do trace */, vl_api_##n##_t_print_json, \
- vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson);
+ vl_msg_api_set_handlers ( \
+ VL_API_##N, #n, vl_api_##n##_t_handler, vl_noop_handler, vl_noop_handler, \
+ vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 1 /* do trace */, \
+ vl_api_##n##_t_print_json, vl_api_##n##_t_tojson, \
+ vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
foreach_plugin_trace_msg;
#undef _