Change 21538: Fix off-by-one in $0 set magic. (From Autrijus.)

2003-10-26 Thread Abhijit Menon-Sen
Change 21538 by [EMAIL PROTECTED] on 2003/10/26 08:08:02

Fix off-by-one in $0 set magic. (From Autrijus.)
The whole PL_origalen thing in perl.c looks very hokey.

Affected files ...

... //depot/perl/mg.c#280 edit

Differences ...

 //depot/perl/mg.c#280 (text) 
Index: perl/mg.c
--- perl/mg.c#279~21440~Sun Oct 12 12:58:05 2003
+++ perl/mg.c   Sun Oct 26 01:08:02 2003
@@ -2403,7 +2403,7 @@
if (len >= (STRLEN)PL_origalen) {
/* Longer than original, will be truncated. */
Copy(s, PL_origargv[0], PL_origalen, char);
-   PL_origargv[0][PL_origalen - 1] = 0;
+   PL_origargv[0][PL_origalen] = 0;
}
else {
/* Shorter than original, will be padded. */
End of Patch.



Change 21541: Integrate:

2003-10-26 Thread Nicholas Clark
Change 21541 by [EMAIL PROTECTED] on 2003/10/26 20:51:55

Integrate:
[ 21535]
Return 21533 (with modifications) having found the problem

(where 21533 is
 Plan C rough edge smoothing. Criteria for a hash split is now
 the earlier of "more keys than buckets" (the old test) or
 linked list too long. Rehash is triggered after a split if the
 longest linked list is too long.)

Affected files ...

... //depot/maint-5.8/perl/hv.c#21 edit
... //depot/maint-5.8/perl/hv.h#9 integrate

Differences ...

 //depot/maint-5.8/perl/hv.c#21 (text) 
Index: perl/hv.c
--- perl/hv.c#20~21519~ Wed Oct 22 12:11:43 2003
+++ perl/hv.c   Sun Oct 26 12:51:55 2003
@@ -20,6 +20,8 @@
 #define PERL_IN_HV_C
 #include "perl.h"
 
+#define HV_MAX_LENGTH_BEFORE_SPLIT 4
+
 STATIC HE*
 S_new_he(pTHX)
 {
@@ -277,6 +279,10 @@
 
 if (HvREHASH(hv)) {
PERL_HASH_INTERNAL(hash, key, klen);
+   /* Yes, you do need this even though you are not "storing" because
+  you can flip the flags below if doing an lval lookup.  (And that
+  was put in to give the semantics Andreas was expecting.)  */
+   flags |= HVhek_REHASH;
 } else {
PERL_HASH(hash, key, klen);
 }
@@ -311,7 +317,7 @@
 }
 else
 HeKFLAGS(entry) = flags;
-if (flags)
+if (flags & HVhek_ENABLEHVKFLAGS)
 HvHASKFLAGS_on(hv);
 }
 if (flags & HVhek_FREEKEY)
@@ -450,6 +456,10 @@
 
 if (HvREHASH(hv)) {
PERL_HASH_INTERNAL(hash, key, klen);
+   /* Yes, you do need this even though you are not "storing" because
+  you can flip the flags below if doing an lval lookup.  (And that
+  was put in to give the semantics Andreas was expecting.)  */
+   flags |= HVhek_REHASH;
 } else if (!hash) {
PERL_HASH(hash, key, klen);
 }
@@ -481,7 +491,7 @@
 }
 else
 HeKFLAGS(entry) = flags;
-if (flags)
+if (flags & HVhek_ENABLEHVKFLAGS)
 HvHASKFLAGS_on(hv);
 }
if (key != keysave)
@@ -597,7 +607,7 @@
  register U32 hash, int flags)
 {
 register XPVHV* xhv;
-register I32 i;
+register U32 n_links;
 register HE *entry;
 register HE **oentry;
 
@@ -644,9 +654,10 @@
 
 /* oentry = &(HvARRAY(hv))[hash & (I32) HvMAX(hv)]; */
 oentry = &((HE**)xhv->xhv_array)[hash & (I32) xhv->xhv_max];
-i = 1;
 
-for (entry = *oentry; entry; i=0, entry = HeNEXT(entry)) {
+n_links = 0;
+
+for (entry = *oentry; entry; ++n_links, entry = HeNEXT(entry)) {
if (HeHASH(entry) != hash)  /* strings can't be equal */
continue;
if (HeKLEN(entry) != (I32)klen)
@@ -713,9 +724,16 @@
 *oentry = entry;
 
 xhv->xhv_keys++; /* HvKEYS(hv)++ */
-if (i) {   /* initial entry? */
+if (!n_links) {/* initial entry? */
xhv->xhv_fill++; /* HvFILL(hv)++ */
-} else if (xhv->xhv_keys > (IV)xhv->xhv_max /* HvKEYS(hv) > HvMAX(hv) */) {
+} else if ((xhv->xhv_keys > (IV)xhv->xhv_max)
+  || ((n_links > HV_MAX_LENGTH_BEFORE_SPLIT) && !HvREHASH(hv))) {
+   /* Use the old HvKEYS(hv) > HvMAX(hv) condition to limit bucket
+  splits on a rehashed hash, as we're not going to split it again,
+  and if someone is lucky (evil) enough to get all the keys in one
+  list they could exhaust our memory as we repeatedly double the
+  number of buckets on every entry. Linear search feels a less worse
+  thing to do.  */
 hsplit(hv);
 }
 
@@ -757,7 +775,7 @@
 XPVHV* xhv;
 char *key;
 STRLEN klen;
-I32 i;
+U32 n_links;
 HE *entry;
 HE **oentry;
 bool is_utf8;
@@ -820,9 +838,9 @@
 
 /* oentry = &(HvARRAY(hv))[hash & (I32) HvMAX(hv)]; */
 oentry = &((HE**)xhv->xhv_array)[hash & (I32) xhv->xhv_max];
-i = 1;
+n_links = 0;
 entry = *oentry;
-for (; entry; i=0, entry = HeNEXT(entry)) {
+for (; entry; ++n_links, entry = HeNEXT(entry)) {
if (HeHASH(entry) != hash)  /* strings can't be equal */
continue;
if (HeKLEN(entry) != (I32)klen)
@@ -876,10 +894,17 @@
 *oentry = entry;
 
 xhv->xhv_keys++; /* HvKEYS(hv)++ */
-if (i) {   /* initial entry? */
+if (!n_links) {/* initial entry? */
xhv->xhv_fill++; /* HvFILL(hv)++ */
-} else if (xhv->xhv_keys > (IV)xhv->xhv_max /* HvKEYS(hv) > HvMAX(hv) */) {
-   hsplit(hv);
+} else if ((xhv->xhv_keys > (IV)xhv->xhv_max)
+  || ((n_links > HV_MAX_LENGTH_BEFORE_SPLIT) && !HvREHASH(hv))) {
+   /* Use only the old HvKEYS(hv) > HvMAX(hv) condition to limit bucket
+  splits on a rehashed hash, as we're not going to split it again,
+  and if someone is 

Change 21542: When %ENV has been turned into a non-magical hash after a

2003-10-26 Thread Rafael Garcia-Suarez
Change 21542 by [EMAIL PROTECTED] on 2003/10/26 21:36:17

When %ENV has been turned into a non-magical hash after a
glob assignment, TAINT_ENV() may dump core because it
assumes $ENV{PATH} is magical. Fix this ; add a test to
verify that the PATH is still checked for taintedness.

Affected files ...

... //depot/perl/t/op/taint.t#57 edit
... //depot/perl/taint.c#35 edit

Differences ...

 //depot/perl/t/op/taint.t#57 (xtext) 
Index: perl/t/op/taint.t
--- perl/t/op/taint.t#56~19358~ Mon Apr 28 01:27:15 2003
+++ perl/t/op/taint.t   Sun Oct 26 13:36:17 2003
@@ -124,7 +124,7 @@
 
 my $TEST = catfile(curdir(), 'TEST');
 
-print "1..206\n";
+print "1..208\n";
 
 # First, let's make sure that Perl is checking the dangerous
 # environment variables. Maybe they aren't set yet, so we'll
@@ -981,4 +981,16 @@
 use re 'taint';
 $TAINT =~ /(.*)/;
 test 206, tainted(my $foo = $1);
+}
+
+{
+# test with a non-magical %ENV (and non-magical %ENV elements)
+our %nonmagicalenv = ( PATH => $TAINT );
+local *ENV = \%nonmagicalenv;
+eval { system("lskdfj"); };
+test 207, $@ =~ /Insecure \$ENV{PATH} while running with -T switch/;
+# [perl #24291] this used to dump core
+%nonmagicalenv = ( PATH => "util" );
+eval { system("lskdfj"); };
+test 208, 1;
 }

 //depot/perl/taint.c#35 (text) 
Index: perl/taint.c
--- perl/taint.c#34~19242~  Wed Apr 16 13:14:01 2003
+++ perl/taint.cSun Oct 26 13:36:17 2003
@@ -80,7 +80,8 @@
NULL
 };
 
-if (!PL_envgv)
+/* Don't bother if there's no %ENV hash */
+if (!PL_envgv || !GvHV(PL_envgv))
return;
 
 #ifdef VMS
@@ -98,7 +99,9 @@
TAINT;
taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
}
-   if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
+   if (SvMAGICAL(*svp)
+   && (mg = mg_find(*svp, PERL_MAGIC_envelem))
+   && MgTAINTEDDIR(mg)) {
TAINT;
taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
}
@@ -113,7 +116,9 @@
TAINT;
taint_proper("Insecure %s%s", "$ENV{PATH}");
}
-   if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
+   if (SvMAGICAL(*svp)
+   && (mg = mg_find(*svp, PERL_MAGIC_envelem))
+   && MgTAINTEDDIR(mg)) {
TAINT;
taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
}
End of Patch.



Change 21540: Fix backward-compatibility issues in if.pm.

2003-10-26 Thread Rafael Garcia-Suarez
Change 21540 by [EMAIL PROTECTED] on 2003/10/26 14:59:53

Fix backward-compatibility issues in if.pm.

Affected files ...

... //depot/perl/lib/if.pm#4 edit

Differences ...

 //depot/perl/lib/if.pm#4 (text) 
Index: perl/lib/if.pm
--- perl/lib/if.pm#3~18684~ Sun Feb  9 17:43:12 2003
+++ perl/lib/if.pm  Sun Oct 26 06:59:53 2003
@@ -1,6 +1,6 @@
 package if;
 
-our $VERSION = '0.03';
+$VERSION = '0.04';
 
 sub work {
   my $method = shift() ? 'import' : 'unimport';
@@ -8,7 +8,7 @@
 
   my $p = $_[0];   # PACKAGE
   (my $file = "$p.pm") =~ s!::!/!g;
-  require $file or die;
+  require $file;
 
   my $m = $p->can($method);
   goto &$m if $m;
End of Patch.



Change 21544: don't complain of podless .pm files that have a separate .pod file

2003-10-26 Thread hv
Change 21544 by [EMAIL PROTECTED] on 2003/10/27 02:51:26

don't complain of podless .pm files that have a separate .pod file

Affected files ...

... //depot/perl/pod/buildtoc#27 edit

Differences ...

 //depot/perl/pod/buildtoc#27 (text) 
Index: perl/pod/buildtoc
--- perl/pod/buildtoc#26~21298~ Sun Sep 21 02:22:57 2003
+++ perl/pod/buildtoc   Sun Oct 26 18:51:26 2003
@@ -203,6 +203,8 @@
   return if $file =~ m!lib/Math/BigInt/t/!;
   return if $file =~ m!/Devel/PPPort/[Hh]arness|lib/Devel/Harness!i;
   return if $file =~ m!XS/(?:APItest|Typemap)!;
+  my $pod = $file;
+  return if $pod =~ s/pm$/pod/ && -e $pod;
   die "$0: tut $File::Find::name" if $file =~ /TUT/;
   unless (open (F, "< $_\0")) {
warn "$0: bogus <$file>: $!";
End of Patch.



Change 21545: fixup separators

2003-10-26 Thread hv
Change 21545 by [EMAIL PROTECTED] on 2003/10/27 02:52:16

fixup separators

Affected files ...

... //depot/perl/Changes#595 edit

Differences ...

 //depot/perl/Changes#595 (text) 
Index: perl/Changes
--- perl/Changes#594~21539~ Sun Oct 26 04:22:54 2003
+++ perl/ChangesSun Oct 26 18:52:16 2003
@@ -30,7 +30,6 @@
 
 
 
-
 [ 21538] By: ams   on 2003/10/26  08:08:02
 Log: Fix off-by-one in $0 set magic. (From Autrijus.)
  The whole PL_origalen thing in perl.c looks very hokey.
@@ -1428,6 +1427,7 @@
 Log: Update changes
  Branch: perl
   ! Changes patchlevel.h
+
 [ 21398] By: hvon 2003/10/02  09:15:42
 Log: build perlapi.pod in deterministic order even when functions differ
  only in case; regen perlapi.pod
End of Patch.