From f957aa538f817b22bf61500bd844048d4706f78f Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 22 Oct 2019 16:18:24 +0200 Subject: [PATCH] jdk: just reserve FDs in 'socketpair' socketpair() is used in libnio/libnet to create "marker FDs", which are only used as destination FD in dup2(). So it is safe to just reserve those descriptors. Otherwise, calling functions may use uninitialized stack variables after successful return of socketpair(), which results in closing arbtrary fds later on. Fixes #192 --- src/app/jdk/lib/jvm/dummies.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/jdk/lib/jvm/dummies.cpp b/src/app/jdk/lib/jvm/dummies.cpp index 910a394..9056c86 100644 --- a/src/app/jdk/lib/jvm/dummies.cpp +++ b/src/app/jdk/lib/jvm/dummies.cpp @@ -10,6 +10,8 @@ extern "C" { #include } +#include + #if 0 #define WARN_NOT_IMPL Genode::warning(__func__, " not implemented (jvm) from ", __builtin_return_address(0)); #else @@ -99,7 +101,14 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) int socketpair(int domain, int type, int protocol, int sv[2]) { - WARN_NOT_IMPL; + /* + * socketpair() is used in libnio/libnet to create "marker FDs", which are + * only used as destination FD in dup2(). So it is safe to just reserve + * those descriptors here. + */ + sv[0] = Libc::file_descriptor_allocator()->alloc(nullptr, nullptr)->libc_fd; + sv[1] = Libc::file_descriptor_allocator()->alloc(nullptr, nullptr)->libc_fd; + return 0; }