Open
Description
Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
pub struct Node {
// The actual tree we belong to. This is unsafe!!
pub tree: *mut Slab<Node>,
/// Our Id
pub id: usize,
/// Our parent's ID
pub parent: Option<usize>,
................................
}
impl Node {
pub fn tree(&self) -> &Slab<Node> {
unsafe { &*self.tree }
}
...........................
}
Considering that tree
is a pub field, I assume that users can directly manipulate this field. This potential situation could result in self.tree
being a null pointer, and directly dereferencing it might trigger undefined behavior (UB).
PoC:
extern crate blitz_dom;
extern crate style;
use blitz_dom::node::Node;
use std::ptr;
use style::{
data::ElementData,
properties::{parse_style_attribute, PropertyDeclarationBlock},
servo_arc::Arc as ServoArc,
shared_lock::{Locked, SharedRwLock},
stylesheets::CssRuleType,
};
use blitz_dom::NodeData;
fn main() {
let node = Node::new(ptr::null_mut(),0,SharedRwLock::new(),NodeData::Document);
let _=node.tree();
}
If there is no external using for Node
, maybe it should not be marked as pub
, at least for its field should not be mark as pub
.
Activity