summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorStanislav Zaikin <stanislav.zaikin@46labs.com>2023-08-01 14:28:37 +0200
committerBeno�t Ganne <bganne@cisco.com>2024-05-03 17:08:55 +0000
commit51e6c0d5febd21e362b34cc54d80419e395a742e (patch)
treefd5722333b34edefd64f69af93e65525aa6487fd /src/vnet
parent616201abe273afb3712791f5b2b8799b5b01a58d (diff)
interface: fix check in set_interface_name api
set_interface_name may crash if wrong sw_if_index is passed e.g. ~0 Type: fix Signed-off-by: Stanislav Zaikin <stanislav.zaikin@46labs.com> Change-Id: Ic7e400c914fb33c2f9eac4f2985bb5b163a18d57
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/interface_api.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c
index 2995836672d..c727e519138 100644
--- a/src/vnet/interface_api.c
+++ b/src/vnet/interface_api.c
@@ -1020,21 +1020,19 @@ vl_api_sw_interface_set_interface_name_t_handler (
{
vl_api_sw_interface_set_interface_name_reply_t *rmp;
vnet_main_t *vnm = vnet_get_main ();
- u32 sw_if_index = ntohl (mp->sw_if_index);
- vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
clib_error_t *error;
int rv = 0;
+ VALIDATE_SW_IF_INDEX (mp);
+
+ u32 sw_if_index = ntohl (mp->sw_if_index);
+ vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
+
if (mp->name[0] == 0)
{
rv = VNET_API_ERROR_INVALID_VALUE;
goto out;
}
- if (si == 0)
- {
- rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
- goto out;
- }
error = vnet_rename_interface (vnm, si->hw_if_index, (char *) mp->name);
if (error)
@@ -1044,6 +1042,7 @@ vl_api_sw_interface_set_interface_name_t_handler (
}
out:
+ BAD_SW_IF_INDEX_LABEL;
REPLY_MACRO (VL_API_SW_INTERFACE_SET_INTERFACE_NAME_REPLY);
}