Skip to content

Commit

Permalink
[Orchagent]: Fixbug segmentfault at routeorch (sonic-net#1025)
Browse files Browse the repository at this point in the history
The log statement will cause segmentfault if `observerEntry->second.routeTable` is empty.

Signed-off-by: Ze Gan <ganze718@gmail.com>
  • Loading branch information
Pterosaur authored and lguohan committed Aug 16, 2019
1 parent 252e12c commit b611808
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr)

observerEntry->second.observers.push_back(observer);

SWSS_LOG_NOTICE("Attached next hop observer of route %s for destination IP %s",
observerEntry->second.routeTable.rbegin()->first.to_string().c_str(),
dstAddr.to_string().c_str());

// Trigger next hop change for the first time the observer is attached
// Note that rbegin() is pointing to the entry with longest prefix match
auto route = observerEntry->second.routeTable.rbegin();
if (route != observerEntry->second.routeTable.rend())
{
SWSS_LOG_NOTICE("Attached next hop observer of route %s for destination IP %s",
observerEntry->second.routeTable.rbegin()->first.to_string().c_str(),
dstAddr.to_string().c_str());
NextHopUpdate update = { dstAddr, route->first, route->second };
observer->update(SUBJECT_TYPE_NEXTHOP_CHANGE, static_cast<void *>(&update));
}
Expand Down

0 comments on commit b611808

Please sign in to comment.