Skip to content

Commit 08a1166

Browse files
committed
fix: add nil checks for bundle data and call pointers
1 parent b22429c commit 08a1166

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

ocppj/dispatcher.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,23 @@ func (d *DefaultServerDispatcher) messagePump() {
543543
log.Error("dispatcher timeout for client %s triggered, but no pending request found", clientID)
544544
continue
545545
}
546+
546547
bundle, _ := el.(RequestBundle)
547-
d.CompleteRequest(clientID, bundle.Call.UniqueId)
548-
log.Infof("request %v for %v timed out", bundle.Call.UniqueId, clientID)
548+
if bundle.Call == nil {
549+
log.Errorf("dispatcher timeout for client %s failed; nil Call attribute", clientID)
550+
continue
551+
}
552+
553+
if bundle.Data == nil {
554+
log.Errorf("dispatcher timeout for client for %s; nil Data attribute", clientID)
555+
continue
556+
}
557+
558+
d.CompleteRequest(clientID, bundle.Call.GetUniqueId())
559+
log.Infof("request %v for %v timed out", bundle.Call.GetUniqueId(), clientID)
549560
if d.onRequestCancel != nil {
550-
d.onRequestCancel(clientID, bundle.Call.UniqueId, bundle.Call.Payload,
551-
ocpp.NewError(GenericError, "Request timed out", bundle.Call.UniqueId))
561+
d.onRequestCancel(clientID, bundle.Call.GetUniqueId(), bundle.Call.Payload,
562+
ocpp.NewError(GenericError, "Request timed out", bundle.Call.GetUniqueId()))
552563
}
553564
}
554565
case clientID = <-d.readyForDispatch:
@@ -590,6 +601,16 @@ func (d *DefaultServerDispatcher) dispatchNextRequest(clientID string) (clientCt
590601
}
591602
el := q.Peek()
592603
bundle, _ := el.(RequestBundle)
604+
if bundle.Call == nil {
605+
log.Errorf("failed to dispatch next request for %s; nil Call attribute", clientID)
606+
return
607+
}
608+
609+
if bundle.Data == nil {
610+
log.Errorf("failed to dispatch next request for %s; nil Data attribute", clientID)
611+
return
612+
}
613+
593614
jsonMessage := bundle.Data
594615
callID := bundle.Call.GetUniqueId()
595616
d.pendingRequestState.AddPendingRequest(clientID, callID, bundle.Call.Payload)

0 commit comments

Comments
 (0)