diff options
author | Mark Geisert <mark@maxrnd.com> | 2020-12-07 02:29:36 -0800 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2020-12-07 16:29:11 +0100 |
commit | 9e573ba50f129bff7b6e1be10cf4bbcb70f1efdd (patch) | |
tree | 7ee98a06dc82c29e8008511e3fcf9a72434846a9 /winsup | |
parent | 58ac5f985c926bfd1b9efbf1a430e826fe3b668c (diff) | |
download | newlib-9e573ba50f129bff7b6e1be10cf4bbcb70f1efdd.zip newlib-9e573ba50f129bff7b6e1be10cf4bbcb70f1efdd.tar.gz newlib-9e573ba50f129bff7b6e1be10cf4bbcb70f1efdd.tar.bz2 |
Cygwin: Allow to set SO_PEERCRED zero (v2)
The existing code errors as EINVAL any attempt to set a value for
SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket. But to
enable the workaround set_no_getpeereid behavior for Python one has
to be able to set SO_PEERCRED to zero. Ergo, this patch. Python has
no way to specify a NULL pointer for 'optval'.
This v2 of patch allows the original working (i.e., allow NULL,0 for
optval,optlen to mean turn off SO_PEERCRED) in addition to the new
working described above. The sense of the 'if' stmt is reversed for
readability.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/fhandler_socket_local.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc index c94bf82..964f3e8 100644 --- a/winsup/cygwin/fhandler_socket_local.cc +++ b/winsup/cygwin/fhandler_socket_local.cc @@ -1430,10 +1430,14 @@ fhandler_socket_local::setsockopt (int level, int optname, const void *optval, FIXME: In the long run we should find a more generic solution which doesn't require a blocking handshake in accept/connect to exchange SO_PEERCRED credentials. */ - if (optval || optlen) - set_errno (EINVAL); - else + /* Temporary: Allow SO_PEERCRED to only be zeroed. Two ways to + accomplish this: pass NULL,0 for optval,optlen; or pass the + address,length of an '(int) 0' set up by the caller. */ + if ((!optval && !optlen) || + (optlen == (socklen_t) sizeof (int) && !*(int *) optval)) ret = af_local_set_no_getpeereid (); + else + set_errno (EINVAL); return ret; case SO_REUSEADDR: |