Skip to content

Commit 12c6345

Browse files
committed
libn/d/overlay: don't deref nil PeerRecord on error
If unmarshaling the peer record fails, there is no need to check if it's a record for a local peer. Attempting to do so anyway will result in a nil-dereference panic. Don't do that. The Windows overlay driver has a typo: prevPeer is being checked twice for whether it was a local-peer record. Check prevPeer once and newPeer once each, as intended. Signed-off-by: Cory Snider <[email protected]>
1 parent e628fa0 commit 12c6345

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

daemon/libnetwork/drivers/overlay/joinleave.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ func (d *driver) EventNotify(nid, tableName, key string, prev, value []byte) {
174174
prevPeer, err = UnmarshalPeerRecord(prev)
175175
if err != nil {
176176
log.G(context.TODO()).WithError(err).Error("Failed to unmarshal previous peer record")
177-
}
178-
if prevPeer.TunnelEndpointIP == d.advertiseAddress {
177+
} else if prevPeer.TunnelEndpointIP == d.advertiseAddress {
179178
// Ignore local peers. We don't add them to the VXLAN
180179
// FDB so don't need to remove them.
181180
prevPeer = nil
@@ -186,8 +185,7 @@ func (d *driver) EventNotify(nid, tableName, key string, prev, value []byte) {
186185
newPeer, err = UnmarshalPeerRecord(value)
187186
if err != nil {
188187
log.G(context.TODO()).WithError(err).Error("Failed to unmarshal peer record")
189-
}
190-
if newPeer.TunnelEndpointIP == d.advertiseAddress {
188+
} else if newPeer.TunnelEndpointIP == d.advertiseAddress {
191189
newPeer = nil
192190
}
193191
}

daemon/libnetwork/drivers/windows/overlay/joinleave_windows.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ func (d *driver) EventNotify(nid, tableName, key string, prev, value []byte) {
7474
prevPeer, err = overlay.UnmarshalPeerRecord(prev)
7575
if err != nil {
7676
log.G(context.TODO()).WithError(err).Error("Failed to unmarshal previous peer record")
77-
}
78-
if prevPeer.TunnelEndpointIP.String() == n.providerAddress {
77+
} else if prevPeer.TunnelEndpointIP.String() == n.providerAddress {
7978
// Ignore local peers. We don't add them to the VXLAN
8079
// FDB so don't need to remove them.
8180
prevPeer = nil
@@ -86,8 +85,7 @@ func (d *driver) EventNotify(nid, tableName, key string, prev, value []byte) {
8685
newPeer, err = overlay.UnmarshalPeerRecord(value)
8786
if err != nil {
8887
log.G(context.TODO()).WithError(err).Error("Failed to unmarshal peer record")
89-
}
90-
if prevPeer.TunnelEndpointIP.String() == n.providerAddress {
88+
} else if newPeer.TunnelEndpointIP.String() == n.providerAddress {
9189
newPeer = nil
9290
}
9391
}

0 commit comments

Comments
 (0)