interface: fix check in set_interface_name api 05/39305/5
authorStanislav Zaikin <stanislav.zaikin@46labs.com>
Tue, 1 Aug 2023 12:28:37 +0000 (14:28 +0200)
committerBeno�t Ganne <bganne@cisco.com>
Fri, 3 May 2024 17:08:55 +0000 (17:08 +0000)
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

src/vnet/interface_api.c

index 2995836..c727e51 100644 (file)
@@ -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);
 }