mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 21:47:15 +03:00
check that the null terminator is defined and not part of a pointer
This commit is contained in:
+2
-2
@@ -536,10 +536,10 @@ pub fn read_c_str(&self, ptr: Pointer) -> EvalResult<'tcx, &[u8]> {
|
||||
let offset = ptr.offset as usize;
|
||||
match alloc.bytes[offset..].iter().position(|&c| c == 0) {
|
||||
Some(size) => {
|
||||
if self.relocations(ptr, size as u64)?.count() != 0 {
|
||||
if self.relocations(ptr, (size + 1) as u64)?.count() != 0 {
|
||||
return Err(EvalError::ReadPointerAsBytes);
|
||||
}
|
||||
self.check_defined(ptr, size as u64)?;
|
||||
self.check_defined(ptr, (size + 1) as u64)?;
|
||||
Ok(&alloc.bytes[offset..offset + size])
|
||||
},
|
||||
None => Err(EvalError::UnterminatedCString(ptr)),
|
||||
|
||||
Reference in New Issue
Block a user