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 19, 2023
1 parent 570ef42 commit 66e7bf5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,15 @@ 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)
extensions, ok := v.Value().([]*ua.ExtensionObject)
if !ok {
return nil, errors.Errorf("unable to find SubscriptionDiagnostics extension objects for sub=%d", s.SubscriptionID)
}
for _, eo := range extensions {
stat, ok := eo.Value.(*ua.SubscriptionDiagnosticsDataType)
if !ok {
continue
}

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

0 comments on commit 66e7bf5

Please sign in to comment.