reactr
reactr copied to clipboard
Invalid input to wasm Runnable causes segfault
With this Rust wasm Runnable:
use suborbital::runnable::*;
use suborbital::resp;
struct ContentType{}
impl Runnable for ContentType {
fn run(&self, input: Vec<u8>) -> Result<Vec<u8>, RunErr> {
let in_string = String::from_utf8(input).unwrap();
resp::content_type("application/json");
Ok(String::from(format!("hello {}", in_string)).as_bytes().to_vec())
}
}
// initialize the runner, do not edit below //
static RUNNABLE: &ContentType = &ContentType{};
#[no_mangle]
pub extern fn init() {
use_runnable(RUNNABLE);
}
and a string input (opposed to the correct CoordinatedRequest) input causes this error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100bfb420]
The stack trace points here: https://github.com/suborbital/reactr/blob/03cc03c6b7c5ab47ef37d3f7518dcd4e3bd863cc/rwasm/api_resp.go#L38
We should be adding a check in rwasm to ensure RequestHandler is not nil before attempting to call anything on it.