public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: Allow to set SO_PEERCRED zero
@ 2020-12-07  6:28 Mark Geisert
  2020-12-07  9:36 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Geisert @ 2020-12-07  6:28 UTC (permalink / raw)
  To: cygwin-patches

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'.

---
 winsup/cygwin/fhandler_socket_local.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
index c94bf828f..421b8bbdb 100644
--- a/winsup/cygwin/fhandler_socket_local.cc
+++ b/winsup/cygwin/fhandler_socket_local.cc
@@ -1430,7 +1430,8 @@ 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)
+	  /* Temporary: Allow only '(int) 0' to be specified. */
+	  if (optlen < (socklen_t) sizeof (int) || 0 != *(int *) optval)
 	    set_errno (EINVAL);
 	  else
 	    ret = af_local_set_no_getpeereid ();
-- 
2.29.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: Allow to set SO_PEERCRED zero
  2020-12-07  6:28 [PATCH] Cygwin: Allow to set SO_PEERCRED zero Mark Geisert
@ 2020-12-07  9:36 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-12-07  9:36 UTC (permalink / raw)
  To: cygwin-patches

Hi Mark,

On Dec  6 22:28, Mark Geisert wrote:
> 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'.
> 
> ---
>  winsup/cygwin/fhandler_socket_local.cc | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
> index c94bf828f..421b8bbdb 100644
> --- a/winsup/cygwin/fhandler_socket_local.cc
> +++ b/winsup/cygwin/fhandler_socket_local.cc
> @@ -1430,7 +1430,8 @@ 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)
> +	  /* Temporary: Allow only '(int) 0' to be specified. */
> +	  if (optlen < (socklen_t) sizeof (int) || 0 != *(int *) optval)
>  	    set_errno (EINVAL);

That breaks existing callers calling setsockopt like this:

  setsockopt (fd, SOL_SOCKET, SO_PEERCRED, NULL, 0);

This should stay backward-compatible.  It should allow the above
as well as your int usage, otherwise postfix will stop working.

Also, please write either

  *(int *) optval != 0

or just

  !!*(int *) optval


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-07  9:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07  6:28 [PATCH] Cygwin: Allow to set SO_PEERCRED zero Mark Geisert
2020-12-07  9:36 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).