From: Stanislav Zaikin Date: Tue, 1 Aug 2023 12:28:37 +0000 (+0200) Subject: interface: fix check in set_interface_name api X-Git-Tag: v24.10-rc0~46 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=51e6c0d5febd21e362b34cc54d80419e395a742e;p=vpp.git 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 Change-Id: Ic7e400c914fb33c2f9eac4f2985bb5b163a18d57 --- 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); }