aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ikev2/ikev2_api.c
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2021-02-16 08:14:31 +0000
committerBeno�t Ganne <bganne@cisco.com>2021-02-16 15:41:55 +0000
commitc2e7e4143ae662cd2426c322c2a85246eeefca1f (patch)
tree6ca57a0431be1729f0c7e8cc7fb616342df00860 /src/plugins/ikev2/ikev2_api.c
parent445d1100587fd3fe533bd201877794555f9593b5 (diff)
ikev2: fix coverity warnings
Type: fix Change-Id: Ia22b1189b82e885eb380f638ea6d05923a858f01 Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'src/plugins/ikev2/ikev2_api.c')
-rw-r--r--src/plugins/ikev2/ikev2_api.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/plugins/ikev2/ikev2_api.c b/src/plugins/ikev2/ikev2_api.c
index 01a7373a6ae..9dab6928fbc 100644
--- a/src/plugins/ikev2/ikev2_api.c
+++ b/src/plugins/ikev2/ikev2_api.c
@@ -43,6 +43,8 @@ extern ikev2_main_t ikev2_main;
#define REPLY_MSG_ID_BASE ikev2_main.msg_id_base
#include <vlibapi/api_helper_macros.h>
+#define IKEV2_MAX_DATA_LEN (1 << 10)
+
static u32
ikev2_encode_sa_index (u32 sai, u32 ti)
{
@@ -542,18 +544,24 @@ static void
vlib_main_t *vm = vlib_get_main ();
clib_error_t *error;
int data_len = ntohl (mp->data_len);
- u8 *tmp = format (0, "%s", mp->name);
- u8 *data = vec_new (u8, data_len);
- clib_memcpy (data, mp->data, data_len);
- error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
- vec_free (tmp);
- vec_free (data);
- if (error)
+ if (data_len > 0 && data_len <= IKEV2_MAX_DATA_LEN)
{
- ikev2_log_error ("%U", format_clib_error, error);
- clib_error_free (error);
- rv = VNET_API_ERROR_UNSPECIFIED;
+ u8 *tmp = format (0, "%s", mp->name);
+ u8 *data = vec_new (u8, data_len);
+ clib_memcpy (data, mp->data, data_len);
+ error =
+ ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
+ vec_free (tmp);
+ vec_free (data);
+ if (error)
+ {
+ ikev2_log_error ("%U", format_clib_error, error);
+ clib_error_free (error);
+ rv = VNET_API_ERROR_UNSPECIFIED;
+ }
}
+ else
+ rv = VNET_API_ERROR_INVALID_VALUE;
#else
rv = VNET_API_ERROR_UNIMPLEMENTED;
#endif
@@ -572,17 +580,22 @@ vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
clib_error_t *error;
u8 *tmp = format (0, "%s", mp->name);
int data_len = ntohl (mp->data_len);
- u8 *data = vec_new (u8, data_len);
- clib_memcpy (data, mp->data, data_len);
- error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
- vec_free (tmp);
- vec_free (data);
- if (error)
+ if (data_len > 0 && data_len <= IKEV2_MAX_DATA_LEN)
{
- ikev2_log_error ("%U", format_clib_error, error);
- clib_error_free (error);
- rv = VNET_API_ERROR_UNSPECIFIED;
+ u8 *data = vec_new (u8, data_len);
+ clib_memcpy (data, mp->data, data_len);
+ error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
+ vec_free (tmp);
+ vec_free (data);
+ if (error)
+ {
+ ikev2_log_error ("%U", format_clib_error, error);
+ clib_error_free (error);
+ rv = VNET_API_ERROR_UNSPECIFIED;
+ }
}
+ else
+ rv = VNET_API_ERROR_INVALID_VALUE;
#else
rv = VNET_API_ERROR_UNIMPLEMENTED;
#endif