[PATCH v3 3/4] ntdll: Error out when trying to use a UDP-only option on a TCP socket

Zebediah Figura (she/her) zfigura at codeweavers.com
Tue Aug 17 12:07:33 CDT 2021


On 8/16/21 11:58 PM, Alex Henrie wrote:
> Windows supports none of these options on TCP. Linux supports all of
> them on TCP. Mac OS supports some of them on TCP, but sets EOPNOTSUPP
> instead of EINVAL for the ones that it doesn't support. So, Wine needs
> to do its own check for whether the option may be used with the socket.
> 
> Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
> ---
> v3: No changes
> ---
>   dlls/ntdll/unix/socket.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
> 
> diff --git a/dlls/ntdll/unix/socket.c b/dlls/ntdll/unix/socket.c
> index 1ac4365c012..4523ded1be7 100644
> --- a/dlls/ntdll/unix/socket.c
> +++ b/dlls/ntdll/unix/socket.c
> @@ -1200,6 +1200,14 @@ static NTSTATUS do_setsockopt( HANDLE handle, IO_STATUS_BLOCK *io, int level,
>   }
>   
>   
> +static BOOL is_datagram_socket( HANDLE handle, IO_STATUS_BLOCK *io )
> +{
> +    int sock_type = -1;
> +    do_getsockopt( handle, io, SOL_SOCKET, SO_TYPE, &sock_type, sizeof(sock_type) );
> +    return sock_type == SOCK_DGRAM;
> +}
> +
> +
>   NTSTATUS sock_ioctl( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user, IO_STATUS_BLOCK *io,
>                        ULONG code, void *in_buffer, ULONG in_size, void *out_buffer, ULONG out_size )
>   {
> @@ -1767,18 +1775,23 @@ NTSTATUS sock_ioctl( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc
>   #endif
>   
>           case IOCTL_AFD_WINE_GET_IP_MULTICAST_IF:
> +            if (!is_datagram_socket( handle, io )) return STATUS_INVALID_PARAMETER;
>               return do_getsockopt( handle, io, IPPROTO_IP, IP_MULTICAST_IF, out_buffer, out_size );
>   

While this will do the right thing if the socket handle is invalid, it's 
a bit ugly. I think it'd be better to check the return value of 
do_getsockopt() in is_datagram_socket(), in which case you also don't 
need to initialize sock_type.

I also don't think it makes sense to pass the IOSB to 
is_datagram_socket(); I'd probably just add a dummy IOSB to 
is_datagram_socket() instead.

Sorry for not mentioning this last time... this was bothering me, but I 
couldn't put my finger on why.



More information about the wine-devel mailing list