Skip to content

Commit c335f9b

Browse files
committed
Fix null pointer dereference in MrpRelay when hasStp is false
MrpRelay::isForwardingInterface() and handleLowerPacket() dereferenced MrpInterfaceData and Ieee8021dInterfaceData pointers without null checks. When hasMrp=true but hasStp=false (e.g. MrpSwitch), Ieee8021dInterfaceData is not added to interfaces, causing a segfault (signal 139). Added null checks: missing MrpInterfaceData now throws a cRuntimeError with a clear message about enabling hasMrp. Missing Ieee8021dInterfaceData is treated as forwarding (following the base class Ieee8021dRelay pattern), since the STP protocol is simply not active.
1 parent 7aae7f2 commit c335f9b

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/inet/linklayer/mrp/MrpRelay.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ void MrpRelay::handleLowerPacket(Packet *incomingPacket)
6464
<< EV_FIELD(incomingPacket) << EV_ENDL;
6565
updatePeerAddress(incomingInterface, sourceAddress, vlanId);
6666

67-
const auto &stpData = incomingInterface->findProtocolData<Ieee8021dInterfaceData>();
68-
const auto &mrpInterfaceData = incomingInterface->findProtocolData<MrpInterfaceData>();
67+
const auto* stpData = incomingInterface->findProtocolData<Ieee8021dInterfaceData>();
68+
const auto* mrpInterfaceData = incomingInterface->findProtocolData<MrpInterfaceData>();
6969

7070
auto outgoingPacket = incomingPacket->dup();
7171
outgoingPacket->trim();
@@ -79,7 +79,9 @@ void MrpRelay::handleLowerPacket(Packet *incomingPacket)
7979
macAddressReq->setSrcAddress(sourceAddress);
8080
macAddressReq->setDestAddress(destinationAddress);
8181

82-
if (mrpInterfaceData->getRole() != MrpInterfaceData::NOTASSIGNED
82+
if (!mrpInterfaceData)
83+
throw cRuntimeError("MrpInterfaceData not found on interface '%s'; enable hasMrp in the network node configuration", incomingInterface->getInterfaceName());
84+
if ((mrpInterfaceData->getRole() != MrpInterfaceData::NOTASSIGNED)
8385
&& isMrpMulticast(destinationAddress)) {
8486
//Mrp-Multicast Handling, forwarding to RingPort according to MrpFilteringDatabase in case incoming interface is not filtering, send up if registered
8587
auto outgoingInterfaceIds = mrpMacForwardingTable->getMrpForwardingInterfaces(destinationAddress, vlanId);
@@ -206,14 +208,13 @@ void MrpRelay::handleLowerPacket(Packet *incomingPacket)
206208

207209
bool MrpRelay::isForwardingInterface(NetworkInterface *networkInterface) const
208210
{
209-
const auto &MrpData = networkInterface->findProtocolData<MrpInterfaceData>();
210-
const auto &Ieee8021dData = networkInterface->findProtocolData<Ieee8021dInterfaceData>();
211211
if (networkInterface->isLoopback() || !networkInterface->isBroadcast())
212212
return false;
213-
else if (!MrpData->isForwarding() || !Ieee8021dData->isForwarding())
214-
return false;
215-
else
216-
return true;
213+
const auto* mrpData = networkInterface->findProtocolData<MrpInterfaceData>();
214+
if (!mrpData)
215+
throw cRuntimeError("MrpInterfaceData not found on interface '%s'; enable hasMrp in the network node configuration", networkInterface->getInterfaceName());
216+
const auto* ieee8021dData = networkInterface->findProtocolData<Ieee8021dInterfaceData>();
217+
return mrpData->isForwarding() && (!ieee8021dData || ieee8021dData->isForwarding());
217218
}
218219

219220
int MrpRelay::getCcmLevel(Packet *packet)

0 commit comments

Comments
 (0)