From db9dc3388d9b565340d47c76626c45e765869cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Mon, 5 Nov 2012 13:27:24 +0100 Subject: [PATCH] Noux: fix resetting fds in unmarshal_fds Since FD_ZERO() resets a whole fd_set (which is 128 bytes) using it to reset dst_fds will override otherwise used memory if the memory was allocated dynamically and is less than sizeof (fd_set). So instead of using this macro we reset the fd_set manually. --- ports/src/lib/libc_noux/plugin.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ports/src/lib/libc_noux/plugin.cc b/ports/src/lib/libc_noux/plugin.cc index 2c5ff1c0a7..6a38e00666 100644 --- a/ports/src/lib/libc_noux/plugin.cc +++ b/ports/src/lib/libc_noux/plugin.cc @@ -241,7 +241,15 @@ static void unmarshal_fds(int *src_fds, size_t src_fds_len, fd_set *dst_fds) { if (!dst_fds) return; - FD_ZERO(dst_fds); + /** + * Calling FD_ZERO will not work because it will try to reset sizeof (fd_set) + * which is typically 128 bytes but dst_fds might by even less bytes large if + * it was allocated dynamically. So we will reset the fd_set manually which + * will work fine as long as we are using FreeBSDs libc - another libc however + * might use a different struct. + */ + for (size_t i = 0; i < src_fds_len; i++) + dst_fds->__fds_bits[i] = 0; for (size_t i = 0; i < src_fds_len; i++) FD_SET(src_fds[i], dst_fds);