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
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46

View file

@ -536,10 +536,10 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
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)),