mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 05:57:03 +03:00
Change invalid pointer read panic into Err.
This commit is contained in:
@@ -7,6 +7,7 @@ pub enum EvalError {
|
||||
InvalidBool,
|
||||
PointerOutOfBounds,
|
||||
InvalidPointerAccess,
|
||||
ReadBytesAsPointer,
|
||||
}
|
||||
|
||||
pub type EvalResult<T> = Result<T, EvalError>;
|
||||
@@ -19,6 +20,8 @@ fn description(&self) -> &str {
|
||||
EvalError::PointerOutOfBounds => "pointer offset outside bounds of allocation",
|
||||
EvalError::InvalidPointerAccess =>
|
||||
"a raw memory access tried to access part of a pointer value as bytes",
|
||||
EvalError::ReadBytesAsPointer =>
|
||||
"attempted to read some raw bytes as a pointer address",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -149,10 +149,10 @@ pub fn read_ptr(&self, ptr: Pointer) -> EvalResult<Pointer> {
|
||||
let bytes = &alloc.bytes[ptr.offset..ptr.offset + POINTER_SIZE];
|
||||
let offset = byteorder::NativeEndian::read_u64(bytes) as usize;
|
||||
|
||||
// TODO(tsion): Return an EvalError here instead of panicking.
|
||||
let alloc_id = *alloc.relocations.get(&ptr.offset).unwrap();
|
||||
|
||||
Ok(Pointer { alloc_id: alloc_id, offset: offset })
|
||||
match alloc.relocations.get(&ptr.offset) {
|
||||
Some(&alloc_id) => Ok(Pointer { alloc_id: alloc_id, offset: offset }),
|
||||
None => Err(EvalError::ReadBytesAsPointer),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(tsion): Detect invalid writes here and elsewhere.
|
||||
|
||||
Reference in New Issue
Block a user