Hi guys,
Currently vapi message length is determined by sizeof(vapi_msg_xxxx) when 
alloced by vapi_msg_alloc. But if the vapi message has a variable length string 
type *string xxx[]* , the message real length can be changed, this will make 
vapi message length check error.

For example, cli_inband message in src/vpp/api/vpe.api

> 
> 
> 
> define cli_inband
> {
> 
> 
> 
> u32 client_index;
> 
> 
> 
> u32 context;
> 
> 
> 
> string cmd[];
> 
> 
> 
> };
> 
> 

in vpp-api/vapi/vpe.api.vapi.h, the message length is calculated to 
sizeof(vapi_msg_cli_inband),

* typedef struct __attribute__ ((__packed__)) {
* vl_api_string_t cmd;
* } vapi_payload_cli_inband;
* 
* typedef struct __attribute__ ((__packed__)) {
* vapi_type_msg_header2_t header;
* vapi_payload_cli_inband payload;
* } vapi_msg_cli_inband;
* 
* static inline vapi_msg_cli_inband* vapi_alloc_cli_inband(struct vapi_ctx_s 
*ctx)
* {
* vapi_msg_cli_inband *msg = NULL;
* const size_t size = sizeof(vapi_msg_cli_inband);
* /* cast here required to play nicely with C++ world ... */
* msg = (vapi_msg_cli_inband*)vapi_msg_alloc(ctx, size);
* if (!msg) {
* return NULL;
* }
* msg->header.client_index = vapi_get_client_index(ctx);
* msg->header.context = 0;
* msg->header._vl_msg_id = vapi_lookup_vl_msg_id(ctx, vapi_msg_id_cli_inband);
* return msg;
* }
* 
* static void
* vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
* {
* vl_api_cli_inband_reply_t *rmp;
* int rv = 0;
* vlib_main_t *vm = vlib_get_main ();
* unformat_input_t input;
* u8 *out_vec = 0;
* u8 *cmd_vec = 0;
* 
* if (vl_msg_api_get_msg_length (mp) <
* vl_api_string_len (&mp->cmd) + sizeof (*mp))
* {
* rv = -1;
* goto error;
* }
* 
* cmd_vec = vl_api_from_api_to_new_vec (mp, &mp->cmd);
* .........
* }

After setting cmd field,  the message real length will more then 
sizeof(vapi_msg_cli_inband), This will make vl_api_cli_inband_t_handler and 
vl_api_from_api_to_new_vec failed.
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#19762): https://lists.fd.io/g/vpp-dev/message/19762
Mute This Topic: https://lists.fd.io/mt/84195057/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to