From fce67f3888d6754fac0ed521a64deb591690d5d3 Mon Sep 17 00:00:00 2001 From: sazeed-nexthop Date: Sat, 27 Jun 2026 08:38:14 +0530 Subject: [PATCH] Guard getNonSflowSampledInterfacePort against an unconfigured management port getNonSflowSampledInterfacePort() and getNonSflowSampledInterfacePortType() index masterLogicalPortIds({PortType::MANAGEMENT_PORT})[0] whenever the ASIC reports isSupported(HwAsic::Feature::MANAGEMENT_PORT). An ASIC can support the management-port feature while a given platform configures no management port, leaving that vector empty so [0] dereferences past the end and the test crashes during setup. Guard the management-port branch with !empty() and fall back to masterLogicalInterfacePortIds()[0] -- the same path taken by platforms whose ASIC does not support a management port. Signed-off-by: sazeed-nexthop --- fboss/agent/test/agent_hw_tests/AgentSflowMirrorTest.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fboss/agent/test/agent_hw_tests/AgentSflowMirrorTest.cpp b/fboss/agent/test/agent_hw_tests/AgentSflowMirrorTest.cpp index f867658e99c3e..7e15e3208da4b 100644 --- a/fboss/agent/test/agent_hw_tests/AgentSflowMirrorTest.cpp +++ b/fboss/agent/test/agent_hw_tests/AgentSflowMirrorTest.cpp @@ -329,13 +329,17 @@ class AgentSflowMirrorTest : public AgentHwTest { } PortID getNonSflowSampledInterfacePort() const { - return checkSameAndGetAsic()->isSupported(HwAsic::Feature::MANAGEMENT_PORT) + return checkSameAndGetAsic()->isSupported( + HwAsic::Feature::MANAGEMENT_PORT) && + !masterLogicalPortIds({cfg::PortType::MANAGEMENT_PORT}).empty() ? masterLogicalPortIds({cfg::PortType::MANAGEMENT_PORT})[0] : masterLogicalInterfacePortIds()[0]; } cfg::PortType getNonSflowSampledInterfacePortType() const { - return checkSameAndGetAsic()->isSupported(HwAsic::Feature::MANAGEMENT_PORT) + return checkSameAndGetAsic()->isSupported( + HwAsic::Feature::MANAGEMENT_PORT) && + !masterLogicalPortIds({cfg::PortType::MANAGEMENT_PORT}).empty() ? cfg::PortType::MANAGEMENT_PORT : cfg::PortType::INTERFACE_PORT; }