Correctly handle possibly misaligned pointers in readdir (#615)

This commit is contained in:
Marcin Mielniczuk
2019-11-28 04:11:32 +01:00
committed by Dan Gohman
parent 16b8b3e58d
commit b69758f672
2 changed files with 3 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ impl<'a> Iterator for ReadDir<'a> {
// Read the data
let dirent_ptr = self.buf.as_ptr() as *const wasi_unstable::Dirent;
let dirent = *dirent_ptr;
let dirent = dirent_ptr.read_unaligned();
let name_ptr = dirent_ptr.offset(1) as *const u8;
// NOTE Linux syscall returns a NULL-terminated name, but WASI doesn't
let namelen = dirent.d_namlen as usize;