From 9b28395f0d314c98079b9abf08302cb9ea1c8399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 16 Jul 2013 13:52:19 +0200 Subject: [PATCH] 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. --- ports/src/noux/main.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ports/src/noux/main.cc b/ports/src/noux/main.cc index 6caa94dfd..e535104a7 100644 --- a/ports/src/noux/main.cc +++ b/ports/src/noux/main.cc @@ -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_envexecve_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(),