go-yara icon indicating copy to clipboard operation
go-yara copied to clipboard

There's no way to return an error from MemoryBlockIterator

Open smoofra opened this issue 1 year ago • 5 comments

In C, a YR_MEMORY_BLOCK_ITERATOR can set last_error from its iteration functions in order to return an error, but this doesn't seem to be accessible from go.

smoofra avatar May 18 '23 18:05 smoofra

Guilty as charged. ;-) I think this was added to YARA for 4.1.0, after I had done the iterator code. Just like file_size.

I have added another interface, MemoryBlockIterator in the iterator-last-error branch. Would you like to have a look if this works for you – and maybe contribute a test case for this? Thanks!

hillu avatar May 19 '23 14:05 hillu

thanks for responding! What you've got would work, but I think returning an error directly from First() and Next() would be more go-like and easier to use. What do you think?

smoofra avatar May 24 '23 16:05 smoofra

Making First, Next return an error would break the API. Perhaps for version 5.0.

hillu avatar May 25 '23 22:05 hillu

doesn't adding a new method to the interface also break the API?

smoofra avatar May 26 '23 02:05 smoofra

doesn't adding a new method to the interface also break the API?

No. For code using go-yara, implementing the extra interface is optional.

Even though this is not the most (Golang-)idiomatic way to signal an error, I can't think of a better alternative. Would you like to contirbute a test case?

hillu avatar May 27 '23 12:05 hillu