Skip to content

Commit cf39db3

Browse files
aykevldeadprogram
authored andcommitted
interp: fix subtle bug in pointer xor
If a pointer value was xor'ed with a value other than 0, it would not have been run at runtime but instead would fall through to the generic integer operations. This would likely result in a "cannot convert pointer to integer" panic. This commit fixes this subtle case.
1 parent 54c07b7 commit cf39db3

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

interp/interpreter.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -736,30 +736,25 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
736736
if err == nil {
737737
// The lhs is a pointer. This sometimes happens for particular
738738
// pointer tricks.
739-
switch inst.opcode {
740-
case llvm.Add:
739+
if inst.opcode == llvm.Add {
741740
// This likely means this is part of a
742741
// unsafe.Pointer(uintptr(ptr) + offset) pattern.
743742
lhsPtr = lhsPtr.addOffset(int64(rhs.Uint()))
744743
locals[inst.localIndex] = lhsPtr
745-
continue
746-
case llvm.Xor:
747-
if rhs.Uint() == 0 {
748-
// Special workaround for strings.noescape, see
749-
// src/strings/builder.go in the Go source tree. This is
750-
// the identity operator, so we can return the input.
751-
locals[inst.localIndex] = lhs
752-
continue
753-
}
754-
default:
744+
} else if inst.opcode == llvm.Xor && rhs.Uint() == 0 {
745+
// Special workaround for strings.noescape, see
746+
// src/strings/builder.go in the Go source tree. This is
747+
// the identity operator, so we can return the input.
748+
locals[inst.localIndex] = lhs
749+
} else {
755750
// Catch-all for weird operations that should just be done
756751
// at runtime.
757752
err := r.runAtRuntime(fn, inst, locals, &mem, indent)
758753
if err != nil {
759754
return nil, mem, err
760755
}
761-
continue
762756
}
757+
continue
763758
}
764759
var result uint64
765760
switch inst.opcode {

0 commit comments

Comments
 (0)