diff --git a/fixtures/sbpf/memcmp_not_matched.so b/fixtures/sbpf/memcmp_not_matched.so index e2fb0b2..8b6eee3 100755 Binary files a/fixtures/sbpf/memcmp_not_matched.so and b/fixtures/sbpf/memcmp_not_matched.so differ diff --git a/pkg/sealevel/sealevel_test.go b/pkg/sealevel/sealevel_test.go index 51c8826..5370ec7 100644 --- a/pkg/sealevel/sealevel_test.go +++ b/pkg/sealevel/sealevel_test.go @@ -313,10 +313,10 @@ func TestInterpreter_Memcmp_Matches(t *testing.T) { } // The TestInterpreter_Memcmp_Does_Not_Match function tests that the memcmp -// syscall works as expected by comparing the string literals "abcdabcd1234" -// and "BLAHabcd1234" +// syscall works as expected by comparing the string literals "Bbcdabcd1234" +// and "aLAHabcd1234" // The expected result is that the two strings do not match and the difference -// between the first non-matching characters (0x61 - 0x42 = 0x1f) is returned, +// between the first non-matching characters (0x42 - 0x61 = -0x1f) is returned, // and the program checks these and returns messages accordingly. func TestInterpreter_Memcmp_Does_Not_Match(t *testing.T) { loader, err := loader.NewLoaderFromBytes(fixtures.Load(t, "sbpf", "memcmp_not_matched.so")) diff --git a/pkg/sealevel/syscalls_mem.go b/pkg/sealevel/syscalls_mem.go index 4450b4a..5afcaaf 100644 --- a/pkg/sealevel/syscalls_mem.go +++ b/pkg/sealevel/syscalls_mem.go @@ -87,7 +87,7 @@ func SyscallMemcmpImpl(vm sbpf.VM, addr1, addr2, n, resultAddr uint64, cuIn int) b1 := slice1[count] b2 := slice2[count] if b1 != b2 { - cmpResult = int32(b1 - b2) + cmpResult = int32(b1) - int32(b2) break } }