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

Segfault in POSIX module #6952

Closed
p5pRT opened this issue Nov 26, 2003 · 8 comments
Closed

Segfault in POSIX module #6952

p5pRT opened this issue Nov 26, 2003 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 26, 2003

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

Searchable as RT24554$

@p5pRT
Copy link
Author

p5pRT commented Nov 26, 2003

From despair@cpan.org

This is a bug report for perl from despair@​cpan.org,
generated with the help of perlbug 1.34 running under perl v5.8.0.


When calling isdigit(undef) function from POSIX.pm we get segfault.



Flags​:
  category=library
  severity=low


Site configuration information for perl v5.8.0​:

Configured by bhcompile at Tue Feb 18 22​:17​:47 EST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration​:
  Platform​:
  osname=linux, osvers=2.4.20-2.48smp, archname=i386-linux-thread-multi
  uname='linux stripples.devel.redhat.com 2.4.20-2.48smp #1 smp thu feb 13 11​:44​:55 est 2003 i686 i686 i386 gnulinux '
  config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -g -Dmyhostname=localhost -Dperladmin=root@​localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
  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 -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
  optimize='-O2 -march=i386 -mcpu=i686 -g',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
  ccversion='', gccversion='3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='gcc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
  perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
  libc=/lib/libc-2.3.1.so, so=so, useshrplib=true, libperl=libperl.so
  gnulibc_version='2.3.1'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
  cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
  MAINT18379


@​INC for perl v5.8.0​:
  /usr/lib/perl5/5.8.0/i386-linux-thread-multi
  /usr/lib/perl5/5.8.0
  /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.0
  /usr/lib/perl5/site_perl
  /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.0
  /usr/lib/perl5/vendor_perl
  /usr/lib/perl5/5.8.0/i386-linux-thread-multi
  /usr/lib/perl5/5.8.0
  .


Environment for perl v5.8.0​:
  HOME=/home/walery
  LANG=ru_RU.koi8r
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/local/bin​:/bin​:/usr/bin​:/usr/X11R6/bin​:/usr/local/tips​:/usr/java/jdk1.3.1/bin​:/home/walery/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2003

From @rgs

SADAHIRO Tomoyuki wrote​:

On Sat, 29 Nov 2003 14​:00​:55 +0100
Rafael Garcia-Suarez <rgarciasuarez@​free.fr> wrote​:

despair@​cpan.org (via RT) wrote​:

When calling isdigit(undef) function from POSIX.pm we get segfault.

Thanks for your report.
I applied a fix to bleadperl as change #21802.
(The bug was introduced by change #17805, so it's present on 5.8.[12]
but not 5.8.0, which has another bug here.)

Well, I don't know whether isalpha() should be equivalent to
/^[[​:alpha​:]]*\z/ or /^[[​:alpha​:]]+\z/.

I actually added a test for POSIX​::isalnum('') and POSIX​::isalnum(undef)
being true.

But, for a replacement of PL_na, might SvPV() macro be better?

The SvPV (actually, SvPV_nolen) actually occurs, via the typemap.

I think another non-string like a reference is better to be treated
as its stringified form rather than as an empty string.
E.g. in older perl, POSIX​::isalpha([]) was false
and POSIX​::isprint([]) was true.

Thanks for pointing this out.
That means that I probably only need to replace the SvPOK in my patch
by a SvOK. Agreed ?

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2003

From @rgs

Rafael Garcia-Suarez wrote​:

SADAHIRO Tomoyuki wrote​:

Well, I don't know whether isalpha() should be equivalent to
/^[[​:alpha​:]]*\z/ or /^[[​:alpha​:]]+\z/.

I actually added a test for POSIX​::isalnum('') and POSIX​::isalnum(undef)
being true.

But, for a replacement of PL_na, might SvPV() macro be better?

The SvPV (actually, SvPV_nolen) actually occurs, via the typemap.

Did I actually wrote three times actually in the same mail ? Yes.
And moreover I replied without noticing you've supplied a patch.
Well, I think mine is a little bit cleaner, macro-proliferation-wise
-- but I patched the wrong test file.

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2003

From BQW10602@nifty.com

On Sat, 29 Nov 2003 14​:00​:55 +0100
Rafael Garcia-Suarez <rgarciasuarez@​free.fr> wrote​:

despair@​cpan.org (via RT) wrote​:

When calling isdigit(undef) function from POSIX.pm we get segfault.

Thanks for your report.
I applied a fix to bleadperl as change #21802.
(The bug was introduced by change #17805, so it's present on 5.8.[12]
but not 5.8.0, which has another bug here.)

Well, I don't know whether isalpha() should be equivalent to
/^[[​:alpha​:]]*\z/ or /^[[​:alpha​:]]+\z/.
But, for a replacement of PL_na, might SvPV() macro be better?

I think another non-string like a reference is better to be treated
as its stringified form rather than as an empty string.
E.g. in older perl, POSIX​::isalpha([]) was false
and POSIX​::isprint([]) was true.

SADAHIRO Tomoyuki

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2003

From BQW10602@nifty.com

isxxx.patch
diff -urN perl-5.8.2/ext/POSIX/POSIX.xs perl-new/ext/POSIX/POSIX.xs
--- perl-5.8.2/ext/POSIX/POSIX.xs	Wed Oct 01 02:10:22 2003
+++ perl-new/ext/POSIX/POSIX.xs	Sat Nov 29 22:12:42 2003
@@ -842,10 +842,12 @@
 
 int
 isalnum(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isalnum(*s))
 		RETVAL = 0;
@@ -854,10 +856,12 @@
 
 int
 isalpha(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isalpha(*s))
 		RETVAL = 0;
@@ -866,10 +870,12 @@
 
 int
 iscntrl(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!iscntrl(*s))
 		RETVAL = 0;
@@ -878,10 +884,12 @@
 
 int
 isdigit(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isdigit(*s))
 		RETVAL = 0;
@@ -890,10 +898,12 @@
 
 int
 isgraph(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isgraph(*s))
 		RETVAL = 0;
@@ -902,10 +912,12 @@
 
 int
 islower(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!islower(*s))
 		RETVAL = 0;
@@ -914,10 +926,12 @@
 
 int
 isprint(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isprint(*s))
 		RETVAL = 0;
@@ -926,10 +940,12 @@
 
 int
 ispunct(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!ispunct(*s))
 		RETVAL = 0;
@@ -938,10 +954,12 @@
 
 int
 isspace(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isspace(*s))
 		RETVAL = 0;
@@ -950,10 +968,12 @@
 
 int
 isupper(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isupper(*s))
 		RETVAL = 0;
@@ -962,10 +982,12 @@
 
 int
 isxdigit(charstring)
-	unsigned char *	charstring
+	SV *	charstring
+    PREINIT:
+	STRLEN	len;
     CODE:
-	unsigned char *s = charstring;
-	unsigned char *e = s + SvCUR(ST(0));
+	unsigned char *s = (unsigned char *) SvPV(charstring, len);
+	unsigned char *e = s + len;
 	for (RETVAL = 1; RETVAL && s < e; s++)
 	    if (!isxdigit(*s))
 		RETVAL = 0;
diff -urN perl-5.8.2/ext/POSIX/t/is.t perl-new/ext/POSIX/t/is.t
--- perl-5.8.2/ext/POSIX/t/is.t	Wed Oct 01 02:10:22 2003
+++ perl-new/ext/POSIX/t/is.t	Sat Nov 29 23:00:56 2003
@@ -52,6 +52,10 @@
    " \t"       => [ qw(space) ],
 
    "abcde\001" => [],
+
+   # An empty string. Always true (al least in old days) [bug #24554]
+   ''     => [ qw(print graph alnum alpha lower upper digit xdigit
+                  punct cntrl space) ],
   );
 
 

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2003

From @rgs

despair@​cpan.org (via RT) wrote​:

When calling isdigit(undef) function from POSIX.pm we get segfault.

Thanks for your report.
I applied a fix to bleadperl as change #21802.
(The bug was introduced by change #17805, so it's present on 5.8.[12]
but not 5.8.0, which has another bug here.)

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2003

@rspier - Status changed from 'new' to 'resolved'

@p5pRT p5pRT closed this as completed Nov 29, 2003
@p5pRT
Copy link
Author

p5pRT commented Nov 30, 2003

From @rgs

SADAHIRO Tomoyuki wrote​:

On Sat, 29 Nov 2003 14​:00​:55 +0100
Rafael Garcia-Suarez <rgarciasuarez@​free.fr> wrote​:

despair@​cpan.org (via RT) wrote​:

When calling isdigit(undef) function from POSIX.pm we get segfault.

Thanks for your report.
I applied a fix to bleadperl as change #21802.
(The bug was introduced by change #17805, so it's present on 5.8.[12]
but not 5.8.0, which has another bug here.)

Well, I don't know whether isalpha() should be equivalent to
/^[[​:alpha​:]]*\z/ or /^[[​:alpha​:]]+\z/.
But, for a replacement of PL_na, might SvPV() macro be better?

Thanks, applied as #21823.

I think another non-string like a reference is better to be treated
as its stringified form rather than as an empty string.
E.g. in older perl, POSIX​::isalpha([]) was false
and POSIX​::isprint([]) was true.

I added also a test for the stringification of references
passed to POSIX​::isXXX().

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