aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-06-23 19:30:10 -0400
committerMike Frysinger <vapier@gentoo.org>2012-06-23 20:02:12 -0400
commitd035e5bb78cb8ac0672f4644854db8a75bc1e2d8 (patch)
tree12bc583328e7b697c3ea0e76b113110e7a5b40c4
parentlibsandbox: regenerate trace headers when autotools change (diff)
downloadsandbox-d035e5bb78cb8ac0672f4644854db8a75bc1e2d8.tar.gz
sandbox-d035e5bb78cb8ac0672f4644854db8a75bc1e2d8.tar.bz2
sandbox-d035e5bb78cb8ac0672f4644854db8a75bc1e2d8.zip
libsandbox: do not leak file handles from tracing checks
Make sure we use O_CLOEXEC, and clean things up before forking off a tracing process. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--libsandbox/wrapper-funcs/__wrapper_exec.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libsandbox/wrapper-funcs/__wrapper_exec.c b/libsandbox/wrapper-funcs/__wrapper_exec.c
index bbdb103..c3536c3 100644
--- a/libsandbox/wrapper-funcs/__wrapper_exec.c
+++ b/libsandbox/wrapper-funcs/__wrapper_exec.c
@@ -26,8 +26,9 @@ static void sb_check_exec(const char *filename, char *const argv[])
int fd;
unsigned char *elf;
struct stat st;
+ bool do_trace = false;
- fd = open(filename, O_RDONLY);
+ fd = open(filename, O_RDONLY|O_CLOEXEC);
if (fd == -1)
return;
if (stat(filename, &st))
@@ -64,8 +65,8 @@ static void sb_check_exec(const char *filename, char *const argv[])
else
PARSE_ELF(64);
- /* We only support tracing of host personality atm */
- trace_main(filename, argv);
+ do_trace = true;
+ /* Now that we're done with stuff, clean up before forking */
done:
@@ -73,6 +74,9 @@ static void sb_check_exec(const char *filename, char *const argv[])
munmap(elf, st.st_size);
out_fd:
close(fd);
+
+ if (do_trace)
+ trace_main(filename, argv);
}
static char **_sb_check_envp(char **envp, bool is_environ)