sim-se: Fix crash in chdirFunc() on nonexistent directory (#277)
This commit fixes a crash in the syscall emulation of the chdir(2) syscall, implemented by chdirFunc() in src/sim/syscall_emul.cc, when passed a nonexistent directory. The buggy code did not check the return value of realpath(). This patch adds code to check the return value of realpath(), and if it is NULL (i.e., there was an error with the requested directory to change to), propagates the error in `errno` to the application. GitHub issue: https://github.com/gem5/gem5/issues/276
This commit is contained in:
@@ -959,7 +959,9 @@ chdirFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname)
|
||||
tgt_cwd = path;
|
||||
} else {
|
||||
char buf[PATH_MAX];
|
||||
tgt_cwd = realpath((p->tgtCwd + "/" + path).c_str(), buf);
|
||||
if (!realpath((p->tgtCwd + "/" + path).c_str(), buf))
|
||||
return -errno;
|
||||
tgt_cwd = buf;
|
||||
}
|
||||
std::string host_cwd = p->checkPathRedirect(tgt_cwd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user