The overflow check in mEMALIGn erroneously checks for INT_MAX,
albeit the input parameter is size_t. Fix this to check for
__SIZE_MAX__ instead. Also, it misses to check the req against
adding the alignment before calling mALLOc.
While at it, add out-of-bounds checks to pvALLOc, nano_memalign,
nano_valloc, and Cygwin's (unused) dlpvalloc.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
First cut. This is currently implemented only for disk files, and
many things still need to be fixed. But it works in limited testing
with the programs scm_rights_{recv,send} in
winsup/cygwin/socket_tests.
Define static helper functions serialize/deserialize in
fhandler_socket_unix.cc. These will be used to support sending file
descriptors via SCM_RIGHTS control messages.
The serialize function creates an 'fh_ser' structure that contains a
copy of the fhandler associated with the file descriptor, with all
allocated memory freed. The structure also contains the Windows pid
of the current process, which deserialize can use for duplicating
handles.
The deserialize function reconstructs an fhandler from an fh_ser
structure, with the handles duplicated into its own process.
For now, serialization and deserialization are fully implemented only
for disk files, and even in that case there are many FIXMEs that need
attention.
This allows duplication of handles from an fhandler created in a
different process. For now, this is implemented only for
fhandler_base and fhandler_disk_file.
Override this in each derived class to give the size of each fhandler
class so that the size can be computed dynamically from an
fhandler_base pointer.
Replace the 'WCHAR pipe_name_buf[48]' class member by 'PWCHAR
pipe_name_buf', and allocate space for the latter as needed.
Change the default constructor to accommodate this change, and add a
destructor that frees the allocated space.
Also change get_pipe_name and clone to accommodate this change.
The autoconf variable all_host is used to make building of the stub
library used by the testsuite conditional on not cross-compiling.
Make it unconditional, so we will notice if it's broken when
cross-compiling.
This includes various changes to create_cmsg_data and
evaluate_cmsg_data. The most important are:
- create_cmsg_data now allows only one SCM_RIGHTS message and one
SCM_CREDENTIALS message.
- evaluate_cmsg_data now truncates the ancillary data to the number of
control messages that will fit in the supplied buffer. Previously
it discarded all control messages if the buffer was too small.
See https://man7.org/linux/man-pages/man7/unix.7.html.
Previously, create_cmsg_data and evaluate_cmsg_data required the
ancillary data to contain only a single control message, of type
SCM_CREDENTIALS. In preparation for supporting SCM_RIGHTS in the
future, allow more than one.
create_cmsg_data now iterates through the specified control messages
and allows both SCM_CREDENTIALS and SCM_RIGHTS. If no SCM_CREDENTIALS
message is present, it creates one. This was previously done in
sendmsg.
evaluate_cmsg_data also iterates through the received control messages
and allows both SCM_CREDENTIALS and SCM_RIGHTS. Control messages of
type SCM_CREDENTIALS are discarded unless the SO_PASSCRED option has
been set.
Update tests.
b55e3f19 was a bit too aggressive in dropping, rather than just
un-exporting these Makefile variables. We need to set these to the
configured host compiler if we are cross-compiling, otherwise they
default to the build compiler.
Also export CC to the mkvers.sh script (which requires it since
4eca5e6a). It's unclear why we can't just cause windres to use the
build 'cpp' as the pre-processor there.
Add a new HANDLE argument to peek_pipe and peek_pipe_poll so that the
caller can specify a pipe handle to use in lieu of get_handle(). Use
this in recvmsg to make the MSG_PEEK flag work for unbound datagram
sockets.
Untested.
If the caller doesn't specify ancillary data, add credentials to the
outgoing packet.
This enables us to satisfy the requirement
(https://man7.org/linux/man-pages/man7/unix.7.html) that a socket with
the SO_PASSCRED option enabled can get the credentials of its peer in
every message it receives.
FIXME: I'm not sure if this is the right way to satisfy that
requirement. A possible alternative would be to arrange for a socket
to be notified when its peer enables SO_PASSCRED.
Call set_nonblocking before creating the pipe so that the pipe is
created with the correct blocking mode.
Also call set_pipe_non_blocking on the second socket so that the
client end of the pipe has the correct blocking mode. This also makes
sure that the client end of the pipe is set to message mode for
reading.
If the caller has requested the source address, try to get it on each
iteration of the main read loop, not just the first. Set msg_namelen
to 0 if it is never received.
If a packet containing control message data is received, don't read
any more packets, even if MSG_WAITALL is set.
The return value is now -NaN.
This fixes a bug in the mingw-w64 code that was imported into Cygwin.
The fix is consistent with Posix and Linux. It is also consistent
with the current mingw-w64 code, with one exception: The mingw-w64
code sets errno to EDOM if the input is -NaN, but this appears to
differ from Posix and Linux.
Addresses: https://cygwin.com/pipermail/cygwin/2020-October/246606.html
- Calling ResizePseudoConsole() generates some escape sequences.
Due to this behaviour, if the output of non-cygwin app is piped
to less, screen is sometimes distorted when the screen is resized.
With this patch, ResizePseudoConsole() is not called if stdout is
redirected.
- If output of non-cygwin process is piped to cygwin process, such
as less, the non-cygwin process sometimes fails to start and hangs.
This patch fixes the issue.
If there's unread data in the pipe from a previous partial read of a
packet, just return. There can't be an administrative packet waiting
to be read in that case.
Define it to be UINT16_MAX, since the pckt_len member of
af_unix_pkt_hdr_t is of type uint16_t.
Previously it was 65536 (== UINT16_MAX + 1), which is 0 when cast to
uint16_t. So an attempt to write a packet of size MAX_AF_PKT_LEN
actually wrote 0 bytes.