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

pp_quotemeta fails when arg == TARG in 5.6.0-RC1 #1323

Closed
p5pRT opened this issue Mar 12, 2000 · 3 comments
Closed

pp_quotemeta fails when arg == TARG in 5.6.0-RC1 #1323

p5pRT opened this issue Mar 12, 2000 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 12, 2000

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

Searchable as RT2348$

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2000

From tom@compton.nu

Created by tom@compton.nu

The following test script fails in 5.6.0-RC1 when built to use
perl's malloc. Other variant's would fail with the system malloc
though​:

my @​l = qw(hello world);
my $x;

foreach $x (@​l)
{
  print "before - $x\n";
  $x = "\Q$x\E";
  print "after - $x\n";
}

The problem arises in pp_quotemeta because both the argument and
the result are using the same SV something that pp_quotemeta can't
cope with.

Specifically in this instance we take s as a pointer to the arg and
then grow the SV to make space for the result. This causes the data
to move, thus invalidating s.

In fact even if the block didn't move the code would fail if any
characters need escaping as the \ character would be written over
the source character before the source character was copied to the
destination.

I'm not quite sure why argument and result are the same though, because
as far as I can tell from opcode.pl Ilya's write direct to lexical TARG
patch is disabled for quotemeta...

Perl Info


Site configuration information for perl v5.6.0:

Configured by tom at Sun Mar 12 13:49:14 GMT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.12-20, archname=i386-linux
    uname='linux gosford.compton.nu 2.2.12-20 #1 mon sep 27 10:25:54 edt 1999 i586 unknown '
    config_args='-des -Dprefix=/usr -Darchname=i386-linux -Dd_dosuid -Dd_semctl_semun -Dusemymalloc -Dcf_email=tom@compton.nu -Ubincompat5005 -Dman3dir=/usr/lib/perl5/man/man3'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    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, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=/lib/libc-2.1.2.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    v5.6.0-RC1


@INC for perl v5.6.0:
    /usr/lib/perl5/5.6.0/i386-linux
    /usr/lib/perl5/5.6.0
    /usr/lib/perl5/site_perl/5.6.0/i386-linux
    /usr/lib/perl5/site_perl/5.6.0
    /usr/lib/perl5/site_perl/5.5.670/i386-linux
    /usr/lib/perl5/site_perl/5.5.670
    /usr/lib/perl5/site_perl/5.5.660/i386-linux
    /usr/lib/perl5/site_perl/5.5.660
    /usr/lib/perl5/site_perl/5.5.650/i386-linux
    /usr/lib/perl5/site_perl/5.5.650
    /usr/lib/perl5/site_perl/5.5.640/i386-linux
    /usr/lib/perl5/site_perl/5.5.640
    /usr/lib/perl5/site_perl
    .


Environment for perl v5.6.0:
    HOME=/home/tom
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/home/tom/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin
    PERL_BADLANG (unset)
    SHELL=/bin/zsh


@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2000

From @gsar

On Sun, 12 Mar 2000 15​:53​:04 GMT, Tom Hughes wrote​:

The following test script fails in 5.6.0-RC1 when built to use
perl's malloc. Other variant's would fail with the system malloc
though​:

my @​l = qw(hello world);
my $x;

foreach $x (@​l)
{
print "before - $x\n";
$x = "\Q$x\E";
print "after - $x\n";
}

The problem arises in pp_quotemeta because both the argument and
the result are using the same SV something that pp_quotemeta can't
cope with.

Thanks for tracking it down. Please try this.

Sarathy
gsar@​ActiveState.com

Inline Patch
-----------------------------------8<-----------------------------------
Change 5683 by gsar@auger on 2000/03/12 20:11:45

	another optimized-OP_SASSIGN bug: ops that were not OA_TARGLEX
	were being mistakenly subverted anyway

Affected files ...

... //depot/perl/dump.c#62 edit
... //depot/perl/op.c#276 edit
... //depot/perl/pod/perldelta.pod#185 edit
... //depot/perl/t/op/misc.t#41 edit

Differences ...

==== //depot/perl/dump.c#62 (text) ====
Index: perl/dump.c
--- perl/dump.c.~1~	Sun Mar 12 12:11:50 2000
+++ perl/dump.c	Sun Mar 12 12:11:50 2000
@@ -429,6 +429,10 @@
     }
     if (o->op_private) {
 	SV *tmpsv = newSVpvn("", 0);
+	if (PL_opargs[o->op_type] & OA_TARGLEX) {
+	    if (o->op_private & OPpTARGET_MY)
+		sv_catpv(tmpsv, ",TARGET_MY");
+	}
 	if (o->op_type == OP_AASSIGN) {
 	    if (o->op_private & OPpASSIGN_COMMON)
 		sv_catpv(tmpsv, ",COMMON");

==== //depot/perl/op.c#276 (text) ====
Index: perl/op.c
--- perl/op.c.~1~	Sun Mar 12 12:11:50 2000
+++ perl/op.c	Sun Mar 12 12:11:50 2000
@@ -6390,19 +6390,16 @@
 		o->op_targ = ix;
 	    }
 #endif
-	    /* FALL THROUGH */
-	case OP_UC:
-	case OP_UCFIRST:
-	case OP_LC:
-	case OP_LCFIRST:
+	    o->op_seq = PL_op_seqmax++;
+	    break;
+
 	case OP_CONCAT:
-	case OP_JOIN:
-	case OP_QUOTEMETA:
 	    if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
 		if (o->op_next->op_private & OPpTARGET_MY) {
 		    if (o->op_flags & OPf_STACKED) /* chained concats */
 			goto ignore_optimization;
 		    else {
+			/* assert(PL_opargs[o->op_type] & OA_TARGLEX); */
 			o->op_targ = o->op_next->op_targ;
 			o->op_next->op_targ = 0;
 			o->op_private |= OPpTARGET_MY;

==== //depot/perl/pod/perldelta.pod#185 (text) ====
Index: perl/pod/perldelta.pod
--- perl/pod/perldelta.pod.~1~	Sun Mar 12 12:11:50 2000
+++ perl/pod/perldelta.pod	Sun Mar 12 12:11:50 2000
@@ -722,7 +722,7 @@
 nor -Duse64bitall.
 
 Last but not least: note that due to Perl's habit of always using
-floating point numbers the quads are still not true integers.
+floating point numbers, the quads are still not true integers.
 When quads overflow their limits (0...18_446_744_073_709_551_615 unsigned,
 -9_223_372_036_854_775_808...9_223_372_036_854_775_807 signed), they
 are silently promoted to floating point numbers, after which they will

==== //depot/perl/t/op/misc.t#41 (xtext) ====
Index: perl/t/op/misc.t
--- perl/t/op/misc.t.~1~	Sun Mar 12 12:11:50 2000
+++ perl/t/op/misc.t	Sun Mar 12 12:11:50 2000
@@ -515,3 +515,33 @@
 print "ok\n";
 EXPECT
 ok
+########
+my @l = qw(hello.* world);
+my $x;
+
+foreach $x (@l) {
+    print "before - $x\n";
+    $x = "\Q$x\E";
+    print "quotemeta - $x\n";
+    $x = "\u$x";
+    print "ucfirst - $x\n";
+    $x = "\l$x";
+    print "lcfirst - $x\n";
+    $x = "\U$x\E";
+    print "uc - $x\n";
+    $x = "\L$x\E";
+    print "lc - $x\n";
+}
+EXPECT
+before - hello.*
+quotemeta - hello\.\*
+ucfirst - Hello\.\*
+lcfirst - hello\.\*
+uc - HELLO\.\*
+lc - hello\.\*
+before - world
+quotemeta - world
+ucfirst - World
+lcfirst - world
+uc - WORLD
+lc - world
End of Patch.

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2000

From [Unknown Contact. See original ticket]

In message <200003122020.MAA02772@​maul.ActiveState.com>
  Gurusamy Sarathy <gsar@​ActiveState.com> wrote​:

On Sun, 12 Mar 2000 15​:53​:04 GMT, Tom Hughes wrote​:

The problem arises in pp_quotemeta because both the argument and
the result are using the same SV something that pp_quotemeta can't
cope with.

Thanks for tracking it down. Please try this.

Yep. With that patch applied Date​::Manip passes all it's self
tests (which is where I distilled that test case from).

Tom

--
Tom Hughes (tom@​compton.nu)
http​://www.compton.nu/
...If you smoke after sex, you're doing it too fast!

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

No branches or pull requests

1 participant