Skip to content

Commit

Permalink
Fix unchecked type assertion in Subscription Stats
Browse files Browse the repository at this point in the history
Fixes the following panic:
github.com/gopcua/opcua.(*Subscription).StatsWithContext(0xc0000a48c0, {0xf66c28, 0x1545c20})
            github.com/gopcua/opcua@v0.3.11/subscription.go:315 +0x207
 github.com/gopcua/opcua.(*Subscription).Stats(...)
            github.com/gopcua/opcua@v0.3.11/subscription.go:296
  • Loading branch information
Jarrah-libremfg committed Oct 20, 2023
1 parent 570ef42 commit e32a4b1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,16 @@ func (s *Subscription) Stats(ctx context.Context) (*ua.SubscriptionDiagnosticsDa
return nil, errors.Errorf("empty SubscriptionDiagnostics for sub=%d", s.SubscriptionID)
}

for _, eo := range v.Value().([]*ua.ExtensionObject) {
stat := eo.Value.(*ua.SubscriptionDiagnosticsDataType)
eos, ok := v.Value().([]*ua.ExtensionObject)
if !ok {
return nil, errors.Errorf("invalid type for SubscriptionDiagnosticsArray. Want []*ua.ExtensionObject. subID=%d nodeID=%s type=%T", s.SubscriptionID, node.String(), v.Value())
}

for _, eo := range eos {
stat, ok := eo.Value.(*ua.SubscriptionDiagnosticsDataType)
if !ok {
continue
}

if stat.SubscriptionID == s.SubscriptionID {
return stat, nil
Expand Down

0 comments on commit e32a4b1

Please sign in to comment.