endoli / endoli/javascriptcore.rs

Unsoundness: `JSValue` (and others) can outlive the `Context`

Abierto
#38 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
54
Forks
4
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hi,

`JSValue`, `JSObject` and others are not restricted in the lifetime, therefore are able to outlive the `Context`, in the best case just crashing the program and in the worst case causing a use-after-free.

The following script reproduces the problem and leads to a segfault (due to an safety check in jsc itself):
```rs
use javascriptcore::*;

fn main() {
let v;
{
let ctx = JSContext::default();
v = evaluate_script(&ctx, "'Hello' + ' ' + 'World'", None, "test.js", 1)
.expect("Failed to evaluate script");
println!("Value: {:?}", v.as_string());
}
println!("Value: {:?}", v.as_string());
}
```

Typically, you would add `PhantomData` to add a phantom lifetime. However, you already hold a raw pointer to the context in these structs and the context should be a widespread object in many real-world users of your bindings, ref-counting the context in Rust with `Arc` might be the best option.

Kind Regards
Tim

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza con la reproducción en Rust del issue y sigue las definiciones de JSContext, JSValue, JSObject y evaluate_script. Confirma el use-after-free después de que finalice el ámbito de Context y, a continuación, determina y documenta un enfoque de ownership seguro con respecto al lifetime. Se considera terminado cuando la reproducción no puede acceder a valores después de que se haya eliminado su Context y el comportamiento de seguridad relevante está cubierto por un test.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, rust
Área
tooling
Tipo de issue
Error
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.