ego
ego copied to clipboard
Nil pointer dereferences exit before calling deferred functions
Issue description
When dereferencing a nil pointer, execution seems to immediately stop, ignoring any deferred function calls. I imagine that due to how the go runtime handles these scenarios and the Intel SGX memory model, this might be a difficult or impossible fix, but I didn't see this behavior in the limitation section of the docs so I thought it would be useful to bring up.
To reproduce
Steps to reproduce the behavior:
Run the following code inside the enclave (just pasting into the helloworld sample in this repo should work):
package main
import (
"fmt"
)
func main() {
type MyStruct struct {
x string
}
var y *MyStruct
defer func() {
fmt.Println("Recovering...")
fmt.Println(recover())
}()
fmt.Println("Before panic")
fmt.Println(y.x)
fmt.Println("After panic")
}
Then run...
ego-go build && ego sign nilpointer && ego run nilpointer
Once execution reaches the nil pointer dereference, it seems to immediately exit with code 255. The output is as follows:
[erthost] loading enclave ...
[erthost] entering enclave ...
[ego] starting application ...
Before panic
Expected behavior
Using go 18.1, go run helloworld.go
exits with code 0 and produces the following output:
Before panic
Recovering...
runtime error: invalid memory address or nil pointer dereference
After panicking, it reaches the deferred function and is able to recover. Furthermore, if that deferred function is removed, the program still prints some info about why it panicked before exiting.
Thanks for bringing this up! I added it to the limitations sections.