Skip to content

Commit 0fccb48

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 following the base class Ieee8021dRelay pattern: treat missing protocol data as forwarding (the protocol is not active, so it does not block the port).
1 parent 7aae7f2 commit 0fccb48

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/inet/linklayer/mrp/MrpRelay.cc

Lines changed: 6 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,7 @@ void MrpRelay::handleLowerPacket(Packet *incomingPacket)
7979
macAddressReq->setSrcAddress(sourceAddress);
8080
macAddressReq->setDestAddress(destinationAddress);
8181

82-
if (mrpInterfaceData->getRole() != MrpInterfaceData::NOTASSIGNED
82+
if ((!mrpInterfaceData || (mrpInterfaceData->getRole() != MrpInterfaceData::NOTASSIGNED))
8383
&& isMrpMulticast(destinationAddress)) {
8484
//Mrp-Multicast Handling, forwarding to RingPort according to MrpFilteringDatabase in case incoming interface is not filtering, send up if registered
8585
auto outgoingInterfaceIds = mrpMacForwardingTable->getMrpForwardingInterfaces(destinationAddress, vlanId);
@@ -206,14 +206,11 @@ void MrpRelay::handleLowerPacket(Packet *incomingPacket)
206206

207207
bool MrpRelay::isForwardingInterface(NetworkInterface *networkInterface) const
208208
{
209-
const auto &MrpData = networkInterface->findProtocolData<MrpInterfaceData>();
210-
const auto &Ieee8021dData = networkInterface->findProtocolData<Ieee8021dInterfaceData>();
211209
if (networkInterface->isLoopback() || !networkInterface->isBroadcast())
212210
return false;
213-
else if (!MrpData->isForwarding() || !Ieee8021dData->isForwarding())
214-
return false;
215-
else
216-
return true;
211+
const auto* mrpData = networkInterface->findProtocolData<MrpInterfaceData>();
212+
const auto* ieee8021dData = networkInterface->findProtocolData<Ieee8021dInterfaceData>();
213+
return (!mrpData || mrpData->isForwarding()) && (!ieee8021dData || ieee8021dData->isForwarding());
217214
}
218215

219216
int MrpRelay::getCcmLevel(Packet *packet)

0 commit comments

Comments
 (0)