noux: construct new child only if binary is valid

If a script is executed which uses a interpreter that does not exist the
construction of the child fails and potentially leaks memory because the
wrong delete operator is called.
Therefore the binary dataspace of the script and the binary dataspace of
the interpreter are now checked before a new child will be created.

Fixes #812.
This commit is contained in:
Josef Söntgen 2013-07-16 13:52:19 +02:00 committed by Norman Feske
parent 3ec16da03f
commit 9b28395f0d
1 changed files with 18 additions and 2 deletions

View File

@ -250,11 +250,18 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
case SYSCALL_EXECVE:
{
/*
* We have to check the dataspace twice because the binary
* could be a script that uses an interpreter which maybe
* does not exist.
*/
Dataspace_capability binary_ds =
_root_dir->dataspace(_sysio->execve_in.filename);
if (!binary_ds.valid())
throw Child::Binary_does_not_exist();
if (!binary_ds.valid()) {
_sysio->error.execve = Sysio::EXECVE_NONEXISTENT;
return false;
}
Child_env<sizeof(_sysio->execve_in.args)>
child_env(_sysio->execve_in.filename, binary_ds,
@ -262,6 +269,15 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
_root_dir->release(_sysio->execve_in.filename, binary_ds);
binary_ds = _root_dir->dataspace(child_env.binary_name());
if (!binary_ds.valid()) {
_sysio->error.execve = Sysio::EXECVE_NONEXISTENT;
return false;
}
_root_dir->release(child_env.binary_name(), binary_ds);
try {
Child *child = new Child(child_env.binary_name(),
parent(),