Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] socket() sometimes does not set $! on failure on win32 #16849

Closed
p5pRT opened this issue Feb 19, 2019 · 8 comments
Closed

[PATCH] socket() sometimes does not set $! on failure on win32 #16849

p5pRT opened this issue Feb 19, 2019 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 19, 2019

Migrated from rt.perl.org#133853 (status was 'resolved')

Searchable as RT133853$

@p5pRT
Copy link
Author

p5pRT commented Feb 19, 2019

From @xenu

C​:\Users\xenu>perl -MData​::Dumper -MSocket -E "socket(my $foo, 111, SOCK_STREAM, IPPROTO_TCP) or die Dumper([$!, $^E, 0+$!, 0+$^E])"
$VAR1 = [
  '',
  '',
  0,
  0
  ];

C​:\Users\xenu>perl -MData​::Dumper -MSocket -E "socket(my $foo, PF_INET, 111, IPPROTO_TCP) or die Dumper([$!, $^E, 0+$!, 0+$^E])"
$VAR1 = [
  '',
  '',
  0,
  0
  ];

C​:\Users\xenu>perl -MData​::Dumper -MSocket -E "socket(my $foo, PF_INET, SOCK_STREAM, 111) or die Dumper([$!, $^E, 0+$!, 0+$^E])"
$VAR1 = [
  '',
  '',
  0,
  0
  ];

Note that it doesn't happen when PERL_ALLOW_NON_IFS_LSP env variable is
set to 1 (because it makes socket() call WSASocket() directly)​:

C​:\Users\xenu>set PERL_ALLOW_NON_IFS_LSP=1
C​:\Users\xenu>perl -MData​::Dumper -MSocket -E "socket(my $foo, PF_INET, SOCK_STREAM, 111) or die Dumper([$!, $^E, 0+$!, 0+$^E])"
$VAR1 = [
  'The requested protocol has not been configured into the system, or no implementation for it exists.',
  'The requested protocol has not been configured into the system, or no implementation for it exists',
  135,
  10043
  ];

@p5pRT
Copy link
Author

p5pRT commented Feb 19, 2019

From @xenu

The patch is attached

@p5pRT
Copy link
Author

p5pRT commented Feb 19, 2019

From @xenu

0001-win32-win32sck.c-better-socket-error-handling.patch
From 4be8e84b8f1be71d87c4380f39e4e39f9f976fac Mon Sep 17 00:00:00 2001
From: Tomasz Konojacki <me@xenu.pl>
Date: Tue, 19 Feb 2019 18:16:06 +0100
Subject: [PATCH] win32/win32sck.c: better socket() error handling

When the protocol passed to socket() is unknown, set errno to
WSAEPROTONOSUPPORT.

[perl #133853]
---
 win32/win32sck.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/win32/win32sck.c b/win32/win32sck.c
index d9d7f3692b..d285ece082 100644
--- a/win32/win32sck.c
+++ b/win32/win32sck.c
@@ -613,7 +613,7 @@ open_ifs_socket(int af, int type, int protocol)
     dTHX;
     char *s;
     unsigned long proto_buffers_len = 0;
-    int error_code;
+    int error_code, found = 0;
     SOCKET out = INVALID_SOCKET;
 
     if ((s = PerlEnv_getenv("PERL_ALLOW_NON_IFS_LSP")) && atoi(s))
@@ -645,11 +645,15 @@ open_ifs_socket(int af, int type, int protocol)
                 if ((proto_buffers[i].dwServiceFlags1 & XP1_IFS_HANDLES) == 0)
                     continue;
 
+                found = 1;
                 convert_proto_info_w2a(&(proto_buffers[i]), &proto_info);
 
                 out = WSASocket(af, type, protocol, &proto_info, 0, 0);
                 break;
             }
+
+            if (!found)
+                WSASetLastError(WSAEPROTONOSUPPORT);
         }
 
         Safefree(proto_buffers);
-- 
2.20.1.windows.1

@p5pRT
Copy link
Author

p5pRT commented Feb 20, 2019

From @tonycoz

On Tue, 19 Feb 2019 09​:31​:34 -0800, me@​xenu.pl wrote​:

The patch is attached

Thanks, applied as 125ddee.

Tony

@p5pRT
Copy link
Author

p5pRT commented Feb 20, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 20, 2019

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.30.0, this and 160 other issues have been
resolved.

Perl 5.30.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.30.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant