af_packet : fix crash on interface creation 50/40250/2
authorhsandid <halsandi@cisco.com>
Wed, 24 Jan 2024 12:58:03 +0000 (13:58 +0100)
committerBeno�t Ganne <bganne@cisco.com>
Mon, 12 Feb 2024 16:29:22 +0000 (16:29 +0000)
Type: fix

Attempting to create a host-interface with an invalid af_packet name
causes a crash, as we attempt to read the contents of a null ptr.

Change-Id: Ia31ae21684c2b66baa1ceaadf29e19fae33c4ed4
Signed-off-by: hsandid <halsandi@cisco.com>
src/plugins/af_packet/af_packet.c

index 7ff30e0..6924542 100644 (file)
@@ -821,13 +821,15 @@ error:
       close (fd2);
       fd2 = -1;
     }
-  vec_foreach_index (i, apif->fds)
-    if (apif->fds[i] != -1)
-      close (apif->fds[i]);
-  vec_free (apif->fds);
+
   vec_free (host_if_name_dup);
+
   if (apif)
     {
+      vec_foreach_index (i, apif->fds)
+       if (apif->fds[i] != -1)
+         close (apif->fds[i]);
+      vec_free (apif->fds);
       memset (apif, 0, sizeof (*apif));
       pool_put (apm->interfaces, apif);
     }