Skip to content

Commit 85d90b1

Browse files
committed
binder: fix out-of-bounds read in getServingNode()
servingNode_ is a std::vector, so indexing it past the end is undefined behavior -- it does not "extend the vector with zeroes" as the comment claimed. registerServingNode()/unregisterServingNode() both guard the size already; getServingNode() did not. Return NODEID_NONE for a UE that has no slot yet, which is what the zero the old code happened to read would have meant anyway. computeD2DCapability() indexed the vector directly with the same problem; route it through getServingNode() instead. Latent in the shipped configurations, since Registration registers every UE at INITSTAGE_SIMU5G_NODE_RELATIONSHIPS, before any lookup.
1 parent abace2a commit 85d90b1

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/simu5g/common/binder/Binder.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ void Binder::unregisterServingNode(MacNodeId enbId, MacNodeId ueId)
240240
MacNodeId Binder::getServingNode(MacNodeId ueId)
241241
{
242242
ASSERT(getNodeTypeById(ueId) == UE);
243-
return servingNode_[num(ueId)]; // overindexing extends vector with zeroes, which is fine
243+
// A UE that has not registered a serving node yet has no slot in the vector.
244+
return num(ueId) < servingNode_.size() ? servingNode_[num(ueId)] : NODEID_NONE;
244245
}
245246

246247
void Binder::registerMasterNode(MacNodeId masterId, MacNodeId slaveId)
@@ -631,7 +632,7 @@ LteD2DMode Binder::computeD2DCapability(MacNodeId src, MacNodeId dst)
631632
LteMacBase *dstMac = getMacFromMacNodeId(dst);
632633
if (dstMac->isD2DCapable()) {
633634
// set the initial mode
634-
if (servingNode_[num(src)] == servingNode_[num(dst)]) {
635+
if (getServingNode(src) == getServingNode(dst)) {
635636
// if served by the same cell, then the mode is selected according to the corresponding parameter
636637
LteMacBase *srcMac = getMacFromMacNodeId(src);
637638
inet::NetworkInterface *srcNic = getContainingNicModule(srcMac);

0 commit comments

Comments
 (0)