Skip to content

Commit fc27603

Browse files
Protick Bhowmickmeta-codesync[bot]
authored andcommitted
Fix undefined behavior in getCabledPortTranceivers for backplane ports
Summary: getCabledPortTranceivers() was dereferencing the optional returned by getTranscieverIdx() without checking if it actually had a value. This worked fine when all cabled ports had transceivers, but breaks for xphy-backplane ports which have no transceiver at all. When getTranscieverIdx() returns nullopt for these ports, dereferencing it is undefined behavior. Tt was reading garbage memory that happened to look like TransceiverID(1). This garbage ID got added to the set of "expected transceivers", causing HW tests to fail with errors like "Transceivers that should be programmed but are not: 1". The fix simply checks has_value() before dereferencing and skips ports that don't have transceivers. Reviewed By: shiva-menta Differential Revision: D91055041 fbshipit-source-id: 07a58a872700b3495e9d468f91396b0da122d6cc
1 parent e882c2a commit fc27603

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fboss/qsfp_service/test/hw_test/HwPortUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,14 @@ std::vector<TransceiverID> getCabledPortTranceivers(
247247
const HwQsfpEnsemble* ensemble) {
248248
std::unordered_set<TransceiverID> transceivers;
249249
// There could be multiple ports in a single transceiver. Therefore use a set
250-
// to get unique cabled transceivers
250+
// to get unique cabled transceivers.
251+
// Note: Some ports (e.g., backplane ports with XPHY) don't have transceivers,
252+
// so we skip them.
251253
for (auto port : getCabledPorts(ensemble)) {
252-
transceivers.insert(*getTranscieverIdx(port, ensemble));
254+
auto tcvrId = getTranscieverIdx(port, ensemble);
255+
if (tcvrId.has_value()) {
256+
transceivers.insert(*tcvrId);
257+
}
253258
}
254259
return std::vector<TransceiverID>(transceivers.begin(), transceivers.end());
255260
}

0 commit comments

Comments
 (0)