From 689331b9607c7bdf455eceff30e21b77fd0ce369 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 17 Aug 2022 15:08:24 +0300 Subject: [PATCH] unwrap: perform consistency check in SessionIterator C# servers with SessionEnabled=false will return iterator IDs and no session IDs which can be reported as an error immediately because the iterator can't be traversed. --- pkg/rpcclient/unwrap/unwrap.go | 3 +++ pkg/rpcclient/unwrap/unwrap_test.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/rpcclient/unwrap/unwrap.go b/pkg/rpcclient/unwrap/unwrap.go index de82e6121..fd1d27a90 100644 --- a/pkg/rpcclient/unwrap/unwrap.go +++ b/pkg/rpcclient/unwrap/unwrap.go @@ -155,6 +155,9 @@ func SessionIterator(r *result.Invoke, err error) (uuid.UUID, result.Iterator, e if !ok { return uuid.UUID{}, result.Iterator{}, errors.New("the item is InteropInterface, but not an Iterator") } + if (r.Session == uuid.UUID{}) && iter.ID != nil { + return uuid.UUID{}, result.Iterator{}, errors.New("server returned iterator ID, but no session ID") + } return r.Session, iter, nil } diff --git a/pkg/rpcclient/unwrap/unwrap_test.go b/pkg/rpcclient/unwrap/unwrap_test.go index 60fc60088..2f895a07e 100644 --- a/pkg/rpcclient/unwrap/unwrap_test.go +++ b/pkg/rpcclient/unwrap/unwrap_test.go @@ -197,8 +197,11 @@ func TestSessionIterator(t *testing.T) { require.Error(t, err) iid := uuid.New() - sid := uuid.New() iter := result.Iterator{ID: &iid} + _, _, err = SessionIterator(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.NewInterop(iter)}}, nil) + require.Error(t, err) + + sid := uuid.New() rs, ri, err := SessionIterator(&result.Invoke{Session: sid, State: "HALT", Stack: []stackitem.Item{stackitem.NewInterop(iter)}}, nil) require.NoError(t, err) require.Equal(t, sid, rs)