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

IO::Poll - undef fd not checked in mask() #7525

Closed
p5pRT opened this issue Oct 6, 2004 · 7 comments
Closed

IO::Poll - undef fd not checked in mask() #7525

p5pRT opened this issue Oct 6, 2004 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 6, 2004

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

Searchable as RT31864$

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2004

From Peter.Dintelmann@dresdner-bank.com

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.35 running under perl v5.8.5.

When IO​::Poll cannot determine the file descriptor of the first
argument passed to the mask() method, STDIN is later polled instead.
This seems to be due to the fact that the undef value returned by
fileno() evaluates to 0 in numeric context.

Consider the following example where accidentally "F" is passed
to mask() instead of "\*F".

  $ truss -tpoll -vpoll perl -MIO​::Poll=POLLIN -e '$p=IO​::Poll->new();
  open F, "/dev/null" or die $!; $p->mask(F=>POLLIN); $p->poll()'
  </dev/null
  poll(0x00035210, 1, -1) = 1
  fd=0 ev=POLLIN rev=POLLIN
  $

The patch below should fix this. Can you please let me know if it is
ok since this is my first patch ever?

TIA,

  Peter

--- /opt/perl/lib/5.8.5/sun4-solaris-thread-multi/IO/Poll.pm Thu Sep 9
14​:45
:54 2004
+++ /var/tmp/Poll.pm Wed Oct 6 10​:30​:50 2004
@​@​ -8,6 +8,7 @​@​
package IO​::Poll;

use strict;
+use Carp;
use IO​::Handle;
use Exporter ();
our(@​ISA, @​EXPORT_OK, @​EXPORT, $VERSION);
@​@​ -46,6 +47,10 @​@​
  my $self = shift;
  my $io = shift;
  my $fd = fileno($io);
+ unless (defined $fd) {
+ carp "Cannot determine the file descriptor of $io";
+ return;
+ }
  if (@​_) {
  my $mask = shift;
  if($mask) {


Flags​:
  category=library
  severity=low


Site configuration information for perl v5.8.5​:

Configured by p013176 at Thu Sep 9 14​:17​:03 CEST 2004.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration​:
  Platform​:
  osname=solaris, osvers=2.9, archname=sun4-solaris-thread-multi
  uname='sunos oikbm03 5.9 generic_112233-01 sun4u sparc sunw,ultra-5_10 '
  config_args='-Dprefix=/opt/perl -Uinstallusrbinperl -Dcc=gcc
-Doptimize=-O2
-Duseshrplib -Duseperlio -Dusethreads -des'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=define use5005threads=undef useithreads=define
usemultiplicity=de
fine
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/inc
lude -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-D_REENTRANT -fno-strict-aliasing -pipe -I/usr/local/include'
  ccversion='', gccversion='3.3.2', gccosandvers='solaris2.9'
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize
=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='gcc', ldflags =' -L/usr/local/lib '
  libpth=/usr/local/lib /usr/lib /usr/ccs/lib
  libs=-lsocket -lnsl -lgdbm -ldl -lm -lpthread -lc
  perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
  libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -R
/opt/perl/lib
/5.8.5/sun4-solaris-thread-multi/CORE'
  cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches​:


@​INC for perl v5.8.5​:
  /opt/perl/lib/5.8.5/sun4-solaris-thread-multi
  /opt/perl/lib/5.8.5
  /opt/perl/lib/site_perl/5.8.5/sun4-solaris-thread-multi
  /opt/perl/lib/site_perl/5.8.5
  /opt/perl/lib/site_perl
  .


Environment for perl v5.8.5​:
  HOME=/export/home/p013176
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/sbin/​:/opt/perl/bin/​:/usr/bin​:/usr/local/bin
  PERL_BADLANG (unset)
  SHELL=/bin/sh

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 2004

From nick@ing-simmons.net

Peter . Dintelmann @​ dresdner-bank . com <perl5-porters@​perl.org> writes​:

# New Ticket Created by Peter.Dintelmann@​dresdner-bank.com
# Please include the string​: [perl #31864]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=31864 >

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.35 running under perl v5.8.5.

When IO​::Poll cannot determine the file descriptor of the first
argument passed to the mask() method, STDIN is later polled instead.
This seems to be due to the fact that the undef value returned by
fileno() evaluates to 0 in numeric context.

I am not sure I like the carp().
This should either be fatal or silent and return false.

Consider the following example where accidentally "F" is passed
to mask() instead of "\*F".

$ truss -tpoll -vpoll perl -MIO​::Poll=POLLIN -e '$p=IO​::Poll->new();
open F, "/dev/null" or die $!; $p->mask(F=>POLLIN); $p->poll()'
</dev/null
poll(0x00035210, 1, -1) = 1
fd=0 ev=POLLIN rev=POLLIN
$

The patch below should fix this. Can you please let me know if it is
ok since this is my first patch ever?

TIA,

Peter

--- /opt/perl/lib/5.8.5/sun4-solaris-thread-multi/IO/Poll.pm Thu Sep 9
14​:45
​:54 2004
+++ /var/tmp/Poll.pm Wed Oct 6 10​:30​:50 2004
@​@​ -8,6 +8,7 @​@​
package IO​::Poll;

use strict;
+use Carp;
use IO​::Handle;
use Exporter ();
our(@​ISA, @​EXPORT_OK, @​EXPORT, $VERSION);
@​@​ -46,6 +47,10 @​@​
my $self = shift;
my $io = shift;
my $fd = fileno($io);
+ unless (defined $fd) {
+ carp "Cannot determine the file descriptor of $io";
+ return;
+ }
if (@​_) {
my $mask = shift;
if($mask) {

---
Flags​:
category=library
severity=low
---
Site configuration information for perl v5.8.5​:

Configured by p013176 at Thu Sep 9 14​:17​:03 CEST 2004.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration​:
Platform​:
osname=solaris, osvers=2.9, archname=sun4-solaris-thread-multi
uname='sunos oikbm03 5.9 generic_112233-01 sun4u sparc sunw,ultra-5_10 '
config_args='-Dprefix=/opt/perl -Uinstallusrbinperl -Dcc=gcc
-Doptimize=-O2
-Duseshrplib -Duseperlio -Dusethreads -des'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=de
fine
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/inc
lude -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='3.3.2', gccosandvers='solaris2.9'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize
=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='gcc', ldflags =' -L/usr/local/lib '
libpth=/usr/local/lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -lgdbm -ldl -lm -lpthread -lc
perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -R
/opt/perl/lib
/5.8.5/sun4-solaris-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches​:

---
@​INC for perl v5.8.5​:
/opt/perl/lib/5.8.5/sun4-solaris-thread-multi
/opt/perl/lib/5.8.5
/opt/perl/lib/site_perl/5.8.5/sun4-solaris-thread-multi
/opt/perl/lib/site_perl/5.8.5
/opt/perl/lib/site_perl
.

---
Environment for perl v5.8.5​:
HOME=/export/home/p013176
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/sbin/​:/opt/perl/bin/​:/usr/bin​:/usr/local/bin
PERL_BADLANG (unset)
SHELL=/bin/sh

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 2004

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

@p5pRT
Copy link
Author

p5pRT commented Oct 11, 2004

From Peter.Dintelmann@dresdner-bank.com

  [ Sorry for the late reply; I did not have access to
  my email for a few days ]

-----Ursprüngliche Nachricht-----
Von​: Nick Ing-Simmons [mailto​:nick@​ing-simmons.net]
Gesendet​: Freitag, 8. Oktober 2004 11​:39
An​: perl5-porters@​perl.org
Cc​: bugs-bitbucket@​rt.perl.org
Betreff​: Re​: [perl #31864] IO​::Poll - undef fd not checked in mask()

Peter . Dintelmann @​ dresdner-bank . com
<perl5-porters@​perl.org> writes​:

# New Ticket Created by Peter.Dintelmann@​dresdner-bank.com
# Please include the string​: [perl #31864]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=31864 >

This is a bug report for perl from
Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.35 running under perl v5.8.5.

When IO​::Poll cannot determine the file descriptor of the first
argument passed to the mask() method, STDIN is later polled instead.
This seems to be due to the fact that the undef value returned by
fileno() evaluates to 0 in numeric context.

I am not sure I like the carp().
This should either be fatal or silent and return false.

  Personally I prefer the silent mode.

--- /opt/perl/lib/5.8.5/sun4-solaris-thread-multi/IO/Poll.pm Thu Sep 9
14​:45​:54 2004
+++ /var/tmp/Poll.pm Mon Oct 11 09​:49​:48 2004
@​@​ -46,6 +46,7 @​@​
  my $self = shift;
  my $io = shift;
  my $fd = fileno($io);
+ return unless defined $fd;
  if (@​_) {
  my $mask = shift;
  if($mask) {

  Is this ok?

Consider the following example where accidentally "F" is passed
to mask() instead of "\*F".

$ truss -tpoll -vpoll perl -MIO​::Poll=POLLIN -e
'$p=IO​::Poll->new();
open F, "/dev/null" or die $!; $p->mask(F=>POLLIN); $p->poll()'
</dev/null
poll(0x00035210, 1, -1) = 1
fd=0 ev=POLLIN rev=POLLIN
$

The patch below should fix this. Can you please let me know if it is
ok since this is my first patch ever?

TIA,

Peter

--- /opt/perl/lib/5.8.5/sun4-solaris-thread-multi/IO/Poll.pm
Thu Sep 9
14​:45
​:54 2004
+++ /var/tmp/Poll.pm Wed Oct 6 10​:30​:50 2004
@​@​ -8,6 +8,7 @​@​
package IO​::Poll;

use strict;
+use Carp;
use IO​::Handle;
use Exporter ();
our(@​ISA, @​EXPORT_OK, @​EXPORT, $VERSION);
@​@​ -46,6 +47,10 @​@​
my $self = shift;
my $io = shift;
my $fd = fileno($io);
+ unless (defined $fd) {
+ carp "Cannot determine the file descriptor of $io";
+ return;
+ }
if (@​_) {
my $mask = shift;
if($mask) {

---
Flags​:
category=library
severity=low
---
Site configuration information for perl v5.8.5​:

Configured by p013176 at Thu Sep 9 14​:17​:03 CEST 2004.

Summary of my perl5 (revision 5 version 8 subversion 5)
configuration​:
Platform​:
osname=solaris, osvers=2.9, archname=sun4-solaris-thread-multi
uname='sunos oikbm03 5.9 generic_112233-01 sun4u sparc
sunw,ultra-5_10 '
config_args='-Dprefix=/opt/perl -Uinstallusrbinperl -Dcc=gcc
-Doptimize=-O2
-Duseshrplib -Duseperlio -Dusethreads -des'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=de
fine
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/inc
lude -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/include'
ccversion='', gccversion='3.3.2', gccosandvers='solaris2.9'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='off_t',
lseeksize
=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='gcc', ldflags =' -L/usr/local/lib '
libpth=/usr/local/lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -lgdbm -ldl -lm -lpthread -lc
perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -R
/opt/perl/lib
/5.8.5/sun4-solaris-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches​:

---
@​INC for perl v5.8.5​:
/opt/perl/lib/5.8.5/sun4-solaris-thread-multi
/opt/perl/lib/5.8.5
/opt/perl/lib/site_perl/5.8.5/sun4-solaris-thread-multi
/opt/perl/lib/site_perl/5.8.5
/opt/perl/lib/site_perl
.

---
Environment for perl v5.8.5​:
HOME=/export/home/p013176
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/sbin/​:/opt/perl/bin/​:/usr/bin​:/usr/local/bin
PERL_BADLANG (unset)
SHELL=/bin/sh

@p5pRT
Copy link
Author

p5pRT commented Oct 14, 2004

From @rgs

Dintelmann, Peter wrote​:

I am not sure I like the carp().
This should either be fatal or silent and return false.

Personally I prefer the silent mode\. 

--- /opt/perl/lib/5.8.5/sun4-solaris-thread-multi/IO/Poll.pm Thu Sep 9
14​:45​:54 2004
+++ /var/tmp/Poll.pm Mon Oct 11 09​:49​:48 2004

Thanks, applied as change #23366 to bleadperl.

@p5pRT p5pRT closed this as completed Oct 14, 2004
@p5pRT
Copy link
Author

p5pRT commented Oct 14, 2004

@rgs - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Oct 15, 2004

From perl5-porters@ton.iguana.be

In article <20041014181157.2bb866a8@​valis.local>,
  Rafael Garcia-Suarez <rgarciasuarez@​mandrakesoft.com> writes​:

Dintelmann, Peter wrote​:

I am not sure I like the carp().
This should either be fatal or silent and return false.

Personally I prefer the silent mode\. 

--- /opt/perl/lib/5.8.5/sun4-solaris-thread-multi/IO/Poll.pm Thu Sep 9
14​:45​:54 2004
+++ /var/tmp/Poll.pm Mon Oct 11 09​:49​:48 2004

Thanks, applied as change #23366 to bleadperl.
May I pipe up that I dislike silent mode very much. This is almost certainly
a user error perl is detecting here and then ignoring instead of helping.
I think a warn is actually apporpiate since it's what the perl builtins do​:

perl -wle 'sysread(undef, $a, 4096); print "foo"'
Name "main​::a" used only once​: possible typo at -e line 1.
Use of uninitialized value in ref-to-glob cast at -e line 1.
sysread() on unopened filehandle at -e line 1.
foo

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