Check for overflow when incrementing the preopen_fd counter. (#157)

If someone somehow defines more preopens than can fit in the
`__wasi_fd_t` index space, we should detect it instead of silently
wrapping around.
This commit is contained in:
Dan Gohman
2019-10-29 17:11:43 -07:00
committed by GitHub
parent de71dbec0d
commit aecec187d7

View File

@@ -135,7 +135,7 @@ impl WasiCtxBuilder {
let mut fe = FdEntry::from(dir)?;
fe.preopen_path = Some(guest_path);
self.fds.insert(preopen_fd, fe);
preopen_fd += 1;
preopen_fd = preopen_fd.checked_add(1).ok_or(Error::ENFILE)?;
}
let env = self