api: fix bug in pcap capture api 36/41936/3
authorHadi Rayan Al-Sandid <[email protected]>
Tue, 26 Nov 2024 16:25:27 +0000 (17:25 +0100)
committerBeno�t Ganne <[email protected]>
Wed, 27 Nov 2024 08:20:17 +0000 (08:20 +0000)
pcap api cleanup can cause crash in certain scenarios
e.g.missing/invalid 'filename' parameter.

Type: fix

Change-Id: I92417765960de84e30ed7cb945d40c50d722fb6c
Signed-off-by: Hadi Rayan Al-Sandid <[email protected]>
src/vnet/interface_api.c
test/test_pcap.py

index 69bf4b7..65f3a02 100644 (file)
@@ -1653,6 +1653,7 @@ vl_api_pcap_trace_on_t_handler (vl_api_pcap_trace_on_t *mp)
   unformat_init_cstring (&drop_err_name, (char *) mp->error);
   unformat_user (&drop_err_name, unformat_vlib_error, vlib_get_main (),
                 &capture_args.drop_err);
+  unformat_free (&drop_err_name);
 
   rv = vnet_pcap_dispatch_trace_configure (&capture_args);
 
@@ -1660,7 +1661,6 @@ vl_api_pcap_trace_on_t_handler (vl_api_pcap_trace_on_t *mp)
 
 out:
   unformat_free (&filename);
-  unformat_free (&drop_err_name);
 
   REPLY_MACRO (VL_API_PCAP_TRACE_ON_REPLY);
 }
index b73a601..1169dcc 100644 (file)
@@ -163,6 +163,16 @@ class TestPcap(VppTestCase):
         os.remove("/tmp/trace_any_filter.pcap")
         os.remove("/tmp/trace_drop_err.pcap")
 
+        # Attempting to start a trace with no filename should return an error
+        with self.vapi.assert_negative_api_retval():
+            self.vapi.pcap_trace_on(
+                capture_rx=True,
+                capture_tx=True,
+                filter=True,
+                max_packets=1000,
+                sw_if_index=0,
+            )
+
 
 if __name__ == "__main__":
     unittest.main(testRunner=VppTestRunner)