From 1a87698423c3b9efcf7452db03bf289dcb4704ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppi...@redhat.com>
Date: Mon, 19 Jun 2017 15:56:28 +0200
Subject: Fix a memory wrap in sv_vcatpvfn_flags()

---
 ...31211-fixup-File-Glob-degenerate-matching.patch | 266 +++++++++++++++++++++
 perl-5.24.1-sprintf-add-memory-wrap-tests.patch    |  74 ++++++
 ...-avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch |  54 +++++
 ...31211-fixup-File-Glob-degenerate-matching.patch | 258 --------------------
 perl.spec                                          |  12 +-
 5 files changed, 405 insertions(+), 259 deletions(-)
 create mode 100644 
perl-5.24.1-perl-131211-fixup-File-Glob-degenerate-matching.patch
 create mode 100644 perl-5.24.1-sprintf-add-memory-wrap-tests.patch
 create mode 100644 perl-5.25.12-avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch
 delete mode 100644 
perl-5.27.0-perl-131211-fixup-File-Glob-degenerate-matching.patch

diff --git a/perl-5.24.1-perl-131211-fixup-File-Glob-degenerate-matching.patch 
b/perl-5.24.1-perl-131211-fixup-File-Glob-degenerate-matching.patch
new file mode 100644
index 0000000..2b490ec
--- /dev/null
+++ b/perl-5.24.1-perl-131211-fixup-File-Glob-degenerate-matching.patch
@@ -0,0 +1,266 @@
+From 30cba075ecbb662b392b2c6e896dec287ea49aa8 Mon Sep 17 00:00:00 2001
+From: Yves Orton <demer...@gmail.com>
+Date: Tue, 25 Apr 2017 15:17:06 +0200
+Subject: [PATCH] fixup File::Glob degenerate matching
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Ported to 5.24.1:
+
+commit 0db967b2e6a4093a6a5f649190159767e5d005e0
+Author: Yves Orton <demer...@gmail.com>
+Date:   Tue Apr 25 15:17:06 2017 +0200
+
+    [perl #131211] fixup File::Glob degenerate matching
+
+    The old code would go quadratic with recursion and backtracking
+    when doing patterns like "a*a*a*a*a*a*a*x" on a file like
+    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".
+
+    This patch changes the code to not recurse, and to not backtrack,
+    as per this article from Russ Cox: https://research.swtch.com/glob
+
+    It also adds a micro-optimisation for M_ONE and M_SET under the new code.
+
+    Thanks to Avar and Russ Cox for helping with this patch, along with
+    Jilles Tjoelker and the rest of the FreeBSD community.
+
+Signed-off-by: Petr Písař <ppi...@redhat.com>
+---
+ MANIFEST                   |  1 +
+ ext/File-Glob/bsd_glob.c   | 64 +++++++++++++++++++++++--------
+ ext/File-Glob/t/rt131211.t | 94 ++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 144 insertions(+), 15 deletions(-)
+ create mode 100644 ext/File-Glob/t/rt131211.t
+
+diff --git a/MANIFEST b/MANIFEST
+index fe045a7..be2a44f 100644
+--- a/MANIFEST
++++ b/MANIFEST
+@@ -3678,6 +3678,7 @@ ext/File-Glob/t/case.t           See if File::Glob works
+ ext/File-Glob/t/global.t      See if File::Glob works
+ ext/File-Glob/TODO            File::Glob extension todo list
+ ext/File-Glob/t/rt114984.t    See if File::Glob works
++ext/File-Glob/t/rt131211.t    See if File::Glob works
+ ext/File-Glob/t/taint.t               See if File::Glob works
+ ext/File-Glob/t/threads.t     See if File::Glob + threads works
+ ext/GDBM_File/GDBM_File.pm    GDBM extension Perl module
+diff --git a/ext/File-Glob/bsd_glob.c b/ext/File-Glob/bsd_glob.c
+index 821ef20..e96fb73 100644
+--- a/ext/File-Glob/bsd_glob.c
++++ b/ext/File-Glob/bsd_glob.c
+@@ -563,8 +563,12 @@ glob0(const Char *pattern, glob_t *pglob)
+                       break;
+               case BG_STAR:
+                       pglob->gl_flags |= GLOB_MAGCHAR;
+-                      /* collapse adjacent stars to one,
+-                       * to avoid exponential behavior
++                        /* Collapse adjacent stars to one.
++                         * This is required to ensure that a pattern like
++                         * "a**" matches a name like "a", as without this
++                         * check when the first star matched everything it 
would
++                         * cause the second star to return a match fail.
++                         * As long ** is folded here this does not happen.
+                        */
+                       if (bufnext == patbuf || bufnext[-1] != M_ALL)
+                               *bufnext++ = M_ALL;
+@@ -909,35 +913,56 @@ globextend(const Char *path, glob_t *pglob, size_t 
*limitp)
+ 
+ 
+ /*
+- * pattern matching function for filenames.  Each occurrence of the *
+- * pattern causes a recursion level.
++ * pattern matching function for filenames using state machine to avoid
++ * recursion. We maintain a "nextp" and "nextn" to allow us to backtrack
++ * without additional callframes, and to do cleanly prune the backtracking
++ * state when multiple '*' (start) matches are included in the patter.
++ *
++ * Thanks to Russ Cox for the improved state machine logic to avoid quadratic
++ * matching on failure.
++ *
++ * https://research.swtch.com/glob
++ *
++ * An example would be a pattern
++ *  ("a*" x 100) . "y"
++ * against a file name like
++ *  ("a" x 100) . "x"
++ *
+  */
+ static int
+ match(Char *name, Char *pat, Char *patend, int nocase)
+ {
+       int ok, negate_range;
+       Char c, k;
++      Char *nextp = NULL;
++      Char *nextn = NULL;
+ 
++    loop:
+       while (pat < patend) {
+               c = *pat++;
+               switch (c & M_MASK) {
+               case M_ALL:
+                       if (pat == patend)
+                               return(1);
+-                      do
+-                          if (match(name, pat, patend, nocase))
+-                                  return(1);
+-                      while (*name++ != BG_EOS)
+-                              ;
+-                      return(0);
++                      if (*name == BG_EOS)
++                              return 0;
++                      nextn = name + 1;
++                      nextp = pat - 1;
++                      break;
+               case M_ONE:
++                        /* since * matches leftmost-shortest first   *
++                         * if we encounter the EOS then backtracking *
++                         * will not help, so we can exit early here. */
+                       if (*name++ == BG_EOS)
+-                              return(0);
++                                return 0;
+                       break;
+               case M_SET:
+                       ok = 0;
++                        /* since * matches leftmost-shortest first   *
++                         * if we encounter the EOS then backtracking *
++                         * will not help, so we can exit early here. */
+                       if ((k = *name++) == BG_EOS)
+-                              return(0);
++                                return 0;
+                       if ((negate_range = ((*pat & M_MASK) == M_NOT)) != 
BG_EOS)
+                               ++pat;
+                       while (((c = *pat++) & M_MASK) != M_END)
+@@ -953,16 +978,25 @@ match(Char *name, Char *pat, Char *patend, int nocase)
+                               } else if (nocase ? (tolower(c) == tolower(k)) 
: (c == k))
+                                       ok = 1;
+                       if (ok == negate_range)
+-                              return(0);
++                              goto fail;
+                       break;
+               default:
+                       k = *name++;
+                       if (nocase ? (tolower(k) != tolower(c)) : (k != c))
+-                              return(0);
++                              goto fail;
+                       break;
+               }
+       }
+-      return(*name == BG_EOS);
++      if (*name == BG_EOS)
++              return 1;
++
++    fail:
++      if (nextn) {
++              pat = nextp;
++              name = nextn;
++              goto loop;
++      }
++      return 0;
+ }
+ 
+ /* Free allocated data belonging to a glob_t structure. */
+diff --git a/ext/File-Glob/t/rt131211.t b/ext/File-Glob/t/rt131211.t
+new file mode 100644
+index 0000000..c1bcbe0
+--- /dev/null
++++ b/ext/File-Glob/t/rt131211.t
+@@ -0,0 +1,94 @@
++use strict;
++use warnings;
++use v5.16.0;
++use File::Temp 'tempdir';
++use File::Spec::Functions;
++use Test::More;
++use Time::HiRes qw(time);
++
++plan tests => 13;
++
++my $path = tempdir uc cleanup => 1;
++my @files= (
++    "x".("a" x 50)."b", # 0
++    "abbbbbbbbbbbbc",   # 1
++    "abbbbbbbbbbbbd",   # 2
++    "aaabaaaabaaaabc",  # 3
++    "pq",               # 4
++    "r",                # 5
++    "rttiiiiiii",       # 6
++    "wewewewewewe",     # 7
++    "weeeweeeweee",     # 8
++    "weewweewweew",     # 9
++    "wewewewewewewewewewewewewewewewewq", # 10
++    "wtttttttetttttttwr", # 11
++);
++
++
++foreach (@files) {
++    open(my $f, ">", catfile $path, $_);
++}
++
++my $elapsed_fail= 0;
++my $elapsed_match= 0;
++my @got_files;
++my @no_files;
++my $count = 0;
++
++while (++$count < 10) {
++    $elapsed_match -= time;
++    @got_files= glob catfile $path, "x".("a*" x $count) . "b";
++    $elapsed_match += time;
++
++    $elapsed_fail -= time;
++    @no_files= glob catfile $path, "x".("a*" x $count) . "c";
++    $elapsed_fail += time;
++    last if $elapsed_fail > $elapsed_match * 100;
++}
++
++is $count,10,
++    "tried all the patterns without bailing out";
++
++cmp_ok $elapsed_fail/$elapsed_match,"<",2,
++    "time to fail less than twice the time to match";
++is "@got_files", catfile($path, $files[0]),
++    "only got the expected file for xa*..b";
++is "@no_files", "", "shouldnt have files for xa*..c";
++
++
++@got_files= glob catfile $path, "a*b*b*b*bc";
++is "@got_files", catfile($path, $files[1]),
++    "only got the expected file for a*b*b*b*bc";
++
++@got_files= sort glob catfile $path, "a*b*b*bc";
++is "@got_files", catfile($path, $files[3])." ".catfile($path,$files[1]),
++    "got the expected two files for a*b*b*bc";
++
++@got_files= sort glob catfile $path, "p*";
++is "@got_files", catfile($path, $files[4]),
++    "p* matches pq";
++
++@got_files= sort glob catfile $path, "r*???????";
++is "@got_files", catfile($path, $files[6]),
++    "r*??????? works as expected";
++
++@got_files= sort glob catfile $path, "w*e*w??e";
++is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8)),
++    "w*e*w??e works as expected";
++
++@got_files= sort glob catfile $path, "w*e*we??";
++is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } 
(7,8,9,10)),
++    "w*e*we?? works as expected";
++
++@got_files= sort glob catfile $path, "w**e**w";
++is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (9)),
++    "w**e**w works as expected";
++
++@got_files= sort glob catfile $path, "*wee*";
++is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (8,9)),
++    "*wee* works as expected";
++
++@got_files= sort glob catfile $path, "we*";
++is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } 
(7,8,9,10)),
++    "we* works as expected";
++
+-- 
+2.9.4
+
diff --git a/perl-5.24.1-sprintf-add-memory-wrap-tests.patch 
b/perl-5.24.1-sprintf-add-memory-wrap-tests.patch
new file mode 100644
index 0000000..a761fed
--- /dev/null
+++ b/perl-5.24.1-sprintf-add-memory-wrap-tests.patch
@@ -0,0 +1,74 @@
+From 08bc282a248b21c92ff45e49490fb95e24358213 Mon Sep 17 00:00:00 2001
+From: David Mitchell <da...@iabyn.com>
+Date: Tue, 9 May 2017 14:29:11 +0100
+Subject: [PATCH] sprintf(): add memory wrap tests
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Ported to 5.24.1:
+
+commit d729f63cc94318c248eab95844cfbed5298a7ecd
+Author: David Mitchell <da...@iabyn.com>
+Date:   Tue May 9 14:29:11 2017 +0100
+
+    sprintf(): add memory wrap tests
+
+    In various places Perl_sv_vcatpvfn_flags() does croak_memory_wrap()
+    (including a couple added by the previous commit to fix RT #131260),
+    but there don't appear to be any tests for them.
+
+    So this commit adds some tests.
+
+Signed-off-by: Petr Písař <ppi...@redhat.com>
+---
+ t/op/sprintf2.t | 29 ++++++++++++++++++++++++++++-
+ 1 file changed, 28 insertions(+), 1 deletion(-)
+
+diff --git a/t/op/sprintf2.t b/t/op/sprintf2.t
+index 43ed919..ef8a743 100644
+--- a/t/op/sprintf2.t
++++ b/t/op/sprintf2.t
+@@ -262,7 +262,7 @@ if ($Config{nvsize} == 8 &&
+     print "# no hexfloat tests\n";
+ }
+ 
+-plan tests => 1408 + ($Q ? 0 : 12) + @hexfloat + 12;
++plan tests => 1408 + ($Q ? 0 : 12) + @hexfloat + 16;
+ 
+ use strict;
+ use Config;
+@@ -749,3 +749,30 @@ SKIP: {
+            "non-canonical form");
+     }
+ }
++
++# check all calls to croak_memory_wrap()
++# RT #131260
++
++{
++    my $s = 8 * $Config{sizesize};
++    my $i = 1;
++    my $max;
++    while ($s--) { $max |= $i; $i <<= 1; }
++    my $max40 = $max - 40; # see the magic fudge factor in sv_vcatpvfn_flags()
++
++    my @tests = (
++                  # format, arg
++                  ["%.${max}a",        1.1 ],
++                  ["%.${max40}a",      1.1 ],
++                  ["%.${max}i",          1 ],
++                  ["%.${max}i",         -1 ],
++    );
++
++    for my $test (@tests) {
++        my ($fmt, $arg) = @$test;
++        eval { my $s = sprintf $fmt, $arg; };
++        like("$@", qr/panic: memory wrap/, qq{memory wrap: "$fmt", "$arg"});
++    }
++}
++
++
+-- 
+2.9.4
+
diff --git a/perl-5.25.12-avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch 
b/perl-5.25.12-avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch
new file mode 100644
index 0000000..eed9c19
--- /dev/null
+++ b/perl-5.25.12-avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch
@@ -0,0 +1,54 @@
+From bd1a29f218b291165e47d9035aaeec14abd9732e Mon Sep 17 00:00:00 2001
+From: David Mitchell <da...@iabyn.com>
+Date: Mon, 8 May 2017 21:06:38 +0100
+Subject: [PATCH] avoid a memory wrap in sv_vcatpvfn_flags()
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+RT #131260
+
+When calculating the new size of PL_efloatbuf, avoid wrapping 'need'.
+
+Signed-off-by: Petr Písař <ppi...@redhat.com>
+---
+ sv.c | 14 +++++++++++---
+ 1 file changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/sv.c b/sv.c
+index e90ea84..9f3e28e 100644
+--- a/sv.c
++++ b/sv.c
+@@ -12448,7 +12448,13 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char 
*const pat, const STRLEN p
+                     need = BIT_DIGITS(i);
+                 } /* if i < 0, the number of digits is hard to predict. */
+           }
+-          need += has_precis ? precis : 6; /* known default */
++
++            {
++                STRLEN pr = has_precis ? precis : 6; /* known default */
++                if (need >= ((STRLEN)~0) - pr)
++                    croak_memory_wrap();
++                need += pr;
++            }
+ 
+           if (need < width)
+               need = width;
+@@ -12519,10 +12525,12 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const 
char *const pat, const STRLEN p
+ 
+ #endif /* HAS_LDBL_SPRINTF_BUG */
+ 
+-          need += 20; /* fudge factor */
++            if (need >= ((STRLEN)~0) - 40)
++                croak_memory_wrap();
++          need += 40; /* fudge factor */
+           if (PL_efloatsize < need) {
+               Safefree(PL_efloatbuf);
+-              PL_efloatsize = need + 20; /* more fudge */
++              PL_efloatsize = need;
+               Newx(PL_efloatbuf, PL_efloatsize, char);
+               PL_efloatbuf[0] = '\0';
+           }
+-- 
+2.9.4
+
diff --git a/perl-5.27.0-perl-131211-fixup-File-Glob-degenerate-matching.patch 
b/perl-5.27.0-perl-131211-fixup-File-Glob-degenerate-matching.patch
deleted file mode 100644
index c52d790..0000000
--- a/perl-5.27.0-perl-131211-fixup-File-Glob-degenerate-matching.patch
+++ /dev/null
@@ -1,258 +0,0 @@
-From 0db967b2e6a4093a6a5f649190159767e5d005e0 Mon Sep 17 00:00:00 2001
-From: Yves Orton <demer...@gmail.com>
-Date: Tue, 25 Apr 2017 15:17:06 +0200
-Subject: [PATCH] [perl #131211] fixup File::Glob degenerate matching
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-The old code would go quadratic with recursion and backtracking
-when doing patterns like "a*a*a*a*a*a*a*x" on a file like
-"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".
-
-This patch changes the code to not recurse, and to not backtrack,
-as per this article from Russ Cox: https://research.swtch.com/glob
-
-It also adds a micro-optimisation for M_ONE and M_SET under the new code.
-
-Thanks to Avar and Russ Cox for helping with this patch, along with
-Jilles Tjoelker and the rest of the FreeBSD community.
-
-Signed-off-by: Petr Písař <ppi...@redhat.com>
----
- MANIFEST                   |  1 +
- ext/File-Glob/bsd_glob.c   | 64 +++++++++++++++++++++++--------
- ext/File-Glob/t/rt131211.t | 94 ++++++++++++++++++++++++++++++++++++++++++++++
- 3 files changed, 144 insertions(+), 15 deletions(-)
- create mode 100644 ext/File-Glob/t/rt131211.t
-
-diff --git a/MANIFEST b/MANIFEST
-index b7b6e74..af0da6c 100644
---- a/MANIFEST
-+++ b/MANIFEST
-@@ -3948,6 +3948,7 @@ ext/File-Glob/t/basic.t          See if File::Glob works
- ext/File-Glob/t/case.t                See if File::Glob works
- ext/File-Glob/t/global.t      See if File::Glob works
- ext/File-Glob/t/rt114984.t    See if File::Glob works
-+ext/File-Glob/t/rt131211.t    See if File::Glob works
- ext/File-Glob/t/taint.t               See if File::Glob works
- ext/File-Glob/t/threads.t     See if File::Glob + threads works
- ext/File-Glob/TODO            File::Glob extension todo list
-diff --git a/ext/File-Glob/bsd_glob.c b/ext/File-Glob/bsd_glob.c
-index 821ef20..e96fb73 100644
---- a/ext/File-Glob/bsd_glob.c
-+++ b/ext/File-Glob/bsd_glob.c
-@@ -563,8 +563,12 @@ glob0(const Char *pattern, glob_t *pglob)
-                       break;
-               case BG_STAR:
-                       pglob->gl_flags |= GLOB_MAGCHAR;
--                      /* collapse adjacent stars to one,
--                       * to avoid exponential behavior
-+                        /* Collapse adjacent stars to one.
-+                         * This is required to ensure that a pattern like
-+                         * "a**" matches a name like "a", as without this
-+                         * check when the first star matched everything it 
would
-+                         * cause the second star to return a match fail.
-+                         * As long ** is folded here this does not happen.
-                        */
-                       if (bufnext == patbuf || bufnext[-1] != M_ALL)
-                               *bufnext++ = M_ALL;
-@@ -909,35 +913,56 @@ globextend(const Char *path, glob_t *pglob, size_t 
*limitp)
- 
- 
- /*
-- * pattern matching function for filenames.  Each occurrence of the *
-- * pattern causes a recursion level.
-+ * pattern matching function for filenames using state machine to avoid
-+ * recursion. We maintain a "nextp" and "nextn" to allow us to backtrack
-+ * without additional callframes, and to do cleanly prune the backtracking
-+ * state when multiple '*' (start) matches are included in the patter.
-+ *
-+ * Thanks to Russ Cox for the improved state machine logic to avoid quadratic
-+ * matching on failure.
-+ *
-+ * https://research.swtch.com/glob
-+ *
-+ * An example would be a pattern
-+ *  ("a*" x 100) . "y"
-+ * against a file name like
-+ *  ("a" x 100) . "x"
-+ *
-  */
- static int
- match(Char *name, Char *pat, Char *patend, int nocase)
- {
-       int ok, negate_range;
-       Char c, k;
-+      Char *nextp = NULL;
-+      Char *nextn = NULL;
- 
-+    loop:
-       while (pat < patend) {
-               c = *pat++;
-               switch (c & M_MASK) {
-               case M_ALL:
-                       if (pat == patend)
-                               return(1);
--                      do
--                          if (match(name, pat, patend, nocase))
--                                  return(1);
--                      while (*name++ != BG_EOS)
--                              ;
--                      return(0);
-+                      if (*name == BG_EOS)
-+                              return 0;
-+                      nextn = name + 1;
-+                      nextp = pat - 1;
-+                      break;
-               case M_ONE:
-+                        /* since * matches leftmost-shortest first   *
-+                         * if we encounter the EOS then backtracking *
-+                         * will not help, so we can exit early here. */
-                       if (*name++ == BG_EOS)
--                              return(0);
-+                                return 0;
-                       break;
-               case M_SET:
-                       ok = 0;
-+                        /* since * matches leftmost-shortest first   *
-+                         * if we encounter the EOS then backtracking *
-+                         * will not help, so we can exit early here. */
-                       if ((k = *name++) == BG_EOS)
--                              return(0);
-+                                return 0;
-                       if ((negate_range = ((*pat & M_MASK) == M_NOT)) != 
BG_EOS)
-                               ++pat;
-                       while (((c = *pat++) & M_MASK) != M_END)
-@@ -953,16 +978,25 @@ match(Char *name, Char *pat, Char *patend, int nocase)
-                               } else if (nocase ? (tolower(c) == tolower(k)) 
: (c == k))
-                                       ok = 1;
-                       if (ok == negate_range)
--                              return(0);
-+                              goto fail;
-                       break;
-               default:
-                       k = *name++;
-                       if (nocase ? (tolower(k) != tolower(c)) : (k != c))
--                              return(0);
-+                              goto fail;
-                       break;
-               }
-       }
--      return(*name == BG_EOS);
-+      if (*name == BG_EOS)
-+              return 1;
-+
-+    fail:
-+      if (nextn) {
-+              pat = nextp;
-+              name = nextn;
-+              goto loop;
-+      }
-+      return 0;
- }
- 
- /* Free allocated data belonging to a glob_t structure. */
-diff --git a/ext/File-Glob/t/rt131211.t b/ext/File-Glob/t/rt131211.t
-new file mode 100644
-index 0000000..c1bcbe0
---- /dev/null
-+++ b/ext/File-Glob/t/rt131211.t
-@@ -0,0 +1,94 @@
-+use strict;
-+use warnings;
-+use v5.16.0;
-+use File::Temp 'tempdir';
-+use File::Spec::Functions;
-+use Test::More;
-+use Time::HiRes qw(time);
-+
-+plan tests => 13;
-+
-+my $path = tempdir uc cleanup => 1;
-+my @files= (
-+    "x".("a" x 50)."b", # 0
-+    "abbbbbbbbbbbbc",   # 1
-+    "abbbbbbbbbbbbd",   # 2
-+    "aaabaaaabaaaabc",  # 3
-+    "pq",               # 4
-+    "r",                # 5
-+    "rttiiiiiii",       # 6
-+    "wewewewewewe",     # 7
-+    "weeeweeeweee",     # 8
-+    "weewweewweew",     # 9
-+    "wewewewewewewewewewewewewewewewewq", # 10
-+    "wtttttttetttttttwr", # 11
-+);
-+
-+
-+foreach (@files) {
-+    open(my $f, ">", catfile $path, $_);
-+}
-+
-+my $elapsed_fail= 0;
-+my $elapsed_match= 0;
-+my @got_files;
-+my @no_files;
-+my $count = 0;
-+
-+while (++$count < 10) {
-+    $elapsed_match -= time;
-+    @got_files= glob catfile $path, "x".("a*" x $count) . "b";
-+    $elapsed_match += time;
-+
-+    $elapsed_fail -= time;
-+    @no_files= glob catfile $path, "x".("a*" x $count) . "c";
-+    $elapsed_fail += time;
-+    last if $elapsed_fail > $elapsed_match * 100;
-+}
-+
-+is $count,10,
-+    "tried all the patterns without bailing out";
-+
-+cmp_ok $elapsed_fail/$elapsed_match,"<",2,
-+    "time to fail less than twice the time to match";
-+is "@got_files", catfile($path, $files[0]),
-+    "only got the expected file for xa*..b";
-+is "@no_files", "", "shouldnt have files for xa*..c";
-+
-+
-+@got_files= glob catfile $path, "a*b*b*b*bc";
-+is "@got_files", catfile($path, $files[1]),
-+    "only got the expected file for a*b*b*b*bc";
-+
-+@got_files= sort glob catfile $path, "a*b*b*bc";
-+is "@got_files", catfile($path, $files[3])." ".catfile($path,$files[1]),
-+    "got the expected two files for a*b*b*bc";
-+
-+@got_files= sort glob catfile $path, "p*";
-+is "@got_files", catfile($path, $files[4]),
-+    "p* matches pq";
-+
-+@got_files= sort glob catfile $path, "r*???????";
-+is "@got_files", catfile($path, $files[6]),
-+    "r*??????? works as expected";
-+
-+@got_files= sort glob catfile $path, "w*e*w??e";
-+is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (7,8)),
-+    "w*e*w??e works as expected";
-+
-+@got_files= sort glob catfile $path, "w*e*we??";
-+is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } 
(7,8,9,10)),
-+    "w*e*we?? works as expected";
-+
-+@got_files= sort glob catfile $path, "w**e**w";
-+is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (9)),
-+    "w**e**w works as expected";
-+
-+@got_files= sort glob catfile $path, "*wee*";
-+is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } (8,9)),
-+    "*wee* works as expected";
-+
-+@got_files= sort glob catfile $path, "we*";
-+is "@got_files", join(" ", sort map { catfile($path, $files[$_]) } 
(7,8,9,10)),
-+    "we* works as expected";
-+
--- 
-2.9.4
-
diff --git a/perl.spec b/perl.spec
index d5f7ed7..b65faf6 100644
--- a/perl.spec
+++ b/perl.spec
@@ -338,7 +338,13 @@ Patch94:        
perl-5.24.1-RT-130624-heap-use-after-free-in-4-arg-substr.patch
 
 # Make File::Glob more resistant against degenerative matching, RT#131211,
 # in upstream after 5.27.0
-Patch95:        
perl-5.27.0-perl-131211-fixup-File-Glob-degenerate-matching.patch
+Patch95:        
perl-5.24.1-perl-131211-fixup-File-Glob-degenerate-matching.patch
+
+# Fix a memory wrap in sv_vcatpvfn_flags(), RT#131260, in upstream after 
5.25.12
+Patch96:        perl-5.25.12-avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch
+# Tests for avoid-a-memory-wrap-in-sv_vcatpvfn_flags.patch, RT#131260,
+# in upstream after 5.27.0
+Patch97:        perl-5.24.1-sprintf-add-memory-wrap-tests.patch
 
 # Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048
 Patch200:       
perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@@ -3073,6 +3079,8 @@ popd
 %patch93 -p1
 %patch94 -p1
 %patch95 -p1
+%patch96 -p1
+%patch97 -p1
 %patch200 -p1
 %patch201 -p1
 
@@ -3150,6 +3158,7 @@ perl -x patchlevel.h \
     'Fedora Patch90: Fix an invalid memory read when parsing a loop variable 
(RT#130814)' \
     'Fedora Patch94: Fix a heap-use-after-free in four-arguments substr call 
(RT#130624)' \
     'Fedora Patch95: Make File::Glob more resistant against degenerative 
matching (RT#131211)' \
+    'Fedora Patch96: Fix a memory wrap in sv_vcatpvfn_flags() (RT#131260)' \
     'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on 
Linux' \
     'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
     %{nil}
@@ -5442,6 +5451,7 @@ popd
 %changelog
 * Fri Jun 16 2017 Petr Pisar <ppi...@redhat.com> - 4:5.24.1-392
 - Make File::Glob more resistant against degenerative matching (RT#131211)
+- Fix a memory wrap in sv_vcatpvfn_flags() (RT#131260)
 
 * Fri Mar 31 2017 Petr Pisar <ppi...@redhat.com> - 4:5.24.1-391
 - Introduce build-conditions for groff, systemtap, syslog tests, and tcsh
-- 
cgit v1.1


        
https://src.fedoraproject.org/cgit/perl.git/commit/?h=f26&id=1a87698423c3b9efcf7452db03bf289dcb4704ee
_______________________________________________
perl-devel mailing list -- perl-devel@lists.fedoraproject.org
To unsubscribe send an email to perl-devel-le...@lists.fedoraproject.org

Reply via email to