check that the null terminator is defined and not part of a pointer

This commit is contained in:
Oliver Schneider
2016-12-15 09:58:41 +01:00
parent 24203602e1
commit fd0c21eeee
+2 -2
View File
@@ -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)),