develooper Front page | perl.perl5.porters | Postings from July 2011

[perl #95586] Several bugs in setting sockets non-blocking in Win32

From:
Stephen Oberholtzer
Date:
July 26, 2011 00:04
Subject:
[perl #95586] Several bugs in setting sockets non-blocking in Win32
Message ID:
rt-3.6.HEAD-7815-1311608650-1369.95586-75-0@perl.org
# New Ticket Created by  Stephen Oberholtzer 
# Please include the string:  [perl #95586]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=95586 >


Cc: support@ActiveState.com
Subject: Several bugs in setting sockets non-blocking in Win32
Message-Id: <5.14.1_2452_1311607512@soberholtzer.freedompay.com>
Reply-To: oliverklozoff@gmail.com
To: perlbug@perl.org
From: oliverklozoff@gmail.com


This is a bug report for perl from oliverklozoff@gmail.com,
generated with the help of perlbug 1.39 running under perl 5.14.1.


-----------------------------------------------------------------
[Please describe your issue here]

While tracking down a problem (POE build fails tests on SysRW tests), I
discovered three bugs in the "io_blocking" function in IO.xs, in the Win32
codepath.

5f1c7092    125	char flags = (char)block;
20caf59d    126	return ioctl(PerlIO_fileno(f), FIONBIO, &flags);
            127	#   else
91f3b821    128	return -1;
20caf59d    129	#   endif
8add82fc    130	#endif


1. Wrong size of 'flag' variable.

ioctl calls win32_ioctl [win32/win32sck.c] which calls ioctlsocket
[http://msdn.microsoft.com/en-us/library/ms738573%28v=vs.85%29.aspx]

ioctlsocket expects an unsigned long, not a char.

This bug was introduced by 5f1c7092739bf7bb81e301f20fd4c428602d6f9b in order
to silence a compiler warning (presumably about an invalid cast).

2. Inverted logic when setting.

'block' is passed more-or-less unmodified to the ioctl function.  However, the
'FIONBIO' operation is to set NON-blocking. So:

$handle->blocking(1)
	makes the socket non-blocking, while

$handle->blocking(0)
	clears the non-blocking flag (and it might not even do that, due to the
	incorrect size of 'flag').
	
3. Incorrect handling of 'no-args-to-get-current-state'.

$handle->blocking(), which is supposed to return the current blocking status,
is equivalent to $handle->blocking(-1).  The Win32 codepath does not check for
this condition, which causes it to do ioctl(handle, FIONBIO, 0xFF) which makes
the socket become nonblocking.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=medium
    module=IO::Handle
---
Site configuration information for perl 5.14.1:

Configured by sshd_server at Thu Jun 16 17:23:59 2011.

Summary of my perl5 (revision 5 version 14 subversion 1) configuration:

  Platform:
    osname=MSWin32, osvers=5.2, archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -Ox -GL
-fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE
-DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO',
    optimize='-MD -Zi -DNDEBUG -Ox -GL -fp:precise',
    cppflags='-DWIN32'
    ccversion='14.00.40310.41', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='__int64', ivsize=8, nvtype='double', nvsize=8,
Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-ltcg  -libpath:"C:\Perl64\lib\CORE"  -machine:AMD64'
    libpth=\lib
    libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib comctl32.lib bufferoverflowU.lib msvcrt.lib
    perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib comctl32.lib bufferoverflowU.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl514.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf -ltcg  -libpath:"C:\Perl64\lib\CORE"  -machine:AMD64'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY

---
@INC for perl 5.14.1:
    C:/Perl64/site/lib
    C:/Perl64/lib
    .

---
Environment for perl 5.14.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=D:\Progz\ARM\ADSv1_1\BIN;C:\Perl64\site\bin;C:\Perl64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program
Files\Intel\DMIX;D:\Progz\TortoiseSVN\bin;D:\Progz\VisualSVN\bin;D:\Progz\PuTTY;D:\GnuWin32\bin;C:\WINDOWS\system32\WindowsPowerShell\v1.0;D:\Progz\Microsoft
SQL Server\80\Tools\Binn\;C:\Perl\site\bin;C:\Perl\bin;D:\Progz\Dig;D:\Progz\TortoiseSVN32\bin
    PERL_BADLANG (unset)
    SHELL (unset)


-- 
-- Stevie-O
Real programmers use COPY CON PROGRAM.EXE




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About