Skip to content
Snippets Groups Projects
Commit 7c7c8d47 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'cwd_fix' into 'master'

Check for ENOENT/ENOTDIR in chdir().

See merge request redox-os/relibc!347
parents e0be4082 1987ae7c
No related branches found
No related tags found
1 merge request!347Check for ENOENT/ENOTDIR in chdir().
Pipeline #10520 failed
use syscall::data::Stat;
use syscall::error::*;
use syscall::flag::*;
......@@ -95,6 +96,13 @@ pub fn chdir(path: &str) -> Result<()> {
let canonicalized = canonicalize_using_cwd(cwd_guard.as_deref(), path).ok_or(Error::new(ENOENT))?;
let fd = syscall::open(&canonicalized, O_STAT | O_CLOEXEC)?;
let mut stat = Stat::default();
if syscall::fstat(fd, &mut stat).is_err() || (stat.st_mode & MODE_TYPE) != MODE_DIR {
return Err(Error::new(ENOTDIR));
}
let _ = syscall::close(fd);
*cwd_guard = Some(canonicalized.into_boxed_str());
// TODO: Check that the dir exists and is a directory.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment