Closed theory closed 4 years ago
This happens because DeepEqual recursively checks every sub-field of every field of the LockedBuffer struct, exported or not. Some of these refer to guard pages which are marked as NOACCESS and so the process triggers an access violation.
What are you trying to do? Comparing the values contained within them can be done with buffer.EqualTo(buffer2.Bytes())
and checking if two variables point to the same structure is a simple pointer comparison: bufferptr1 == bufferptr2
(where var bufferptri *LockedBuffer
).
I figured it was something like that. Would it be possible to get it to emit an error message to that effect? The segfault is a bit alarming.
I was updating a project with unit tests using Testify's Equal()
function, which ultimately calls memguard.DeepEqual(). The code reads a secret from a config file into a struct with a LockedBuffer field, and I was comparing the structs. I can work around it by comparing the LockedBuffer field with EqualTo()
, and think nil
out the field to compare the rest of the struct, not a big deal, though a bit fussy.
The kernel throws the error because the process reads from memory that it doesn't have permission to read from. I believe you can convert crashes to panics and then use recover to stop the crash if you want to, but there's no way to catch segmentation faults globally in Go.
Describe the bug
I get a segfault when I try to compare two LockedBuffers with reflect.DeepEqual
To Reproduce
Run this:
Output:
Expected behaviour No error.
System (please complete the following information):