summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig A. Berry <craigberry@mac.com>2011-08-19 10:14:13 -0500
committerCraig A. Berry <craigberry@mac.com>2011-09-04 16:14:28 -0500
commitd2457f2a596eb9f4f49750c56d95a24072d49759 (patch)
tree6f27de45d0b3818035ab6de1179c0f63f1a6422b
parent558e0afd4ec40729992d42ffec33aff3aad855b1 (diff)
downloadperl-d2457f2a596eb9f4f49750c56d95a24072d49759.tar.gz
Plug segfault in bsd_glob() with unsupported ALTDIRFUNC flag.
First, disable all the unsupported flags just to make sure they aren't triggering something they shouldn't be. Also, zero the pglob struct before passing to bsd_glob(); it contains function pointers, and it's safest if they are null rather than containing random stack data. Bug reported by Clément Lecigne <clemun@gmail.com>.
-rw-r--r--ext/File-Glob/Glob.pm2
-rw-r--r--ext/File-Glob/Glob.xs3
-rw-r--r--ext/File-Glob/t/basic.t6
3 files changed, 9 insertions, 2 deletions
diff --git a/ext/File-Glob/Glob.pm b/ext/File-Glob/Glob.pm
index 7c6b92cf41..8bc4677339 100644
--- a/ext/File-Glob/Glob.pm
+++ b/ext/File-Glob/Glob.pm
@@ -56,7 +56,7 @@ use XSLoader ();
) ],
);
-$VERSION = '1.07';
+$VERSION = '1.07_01';
sub import {
require Exporter;
diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
index 59345e7e92..f676a303da 100644
--- a/ext/File-Glob/Glob.xs
+++ b/ext/File-Glob/Glob.xs
@@ -49,9 +49,12 @@ PPCODE:
/* allow for optional flags argument */
if (items > 1) {
flags = (int) SvIV(ST(1));
+ /* remove unsupported flags */
+ flags &= ~(GLOB_APPEND | GLOB_DOOFFS | GLOB_ALTDIRFUNC | GLOB_MAGCHAR);
}
/* call glob */
+ bzero(&pglob, sizeof(glob_t));
retval = bsd_glob(pattern, flags, errfunc, &pglob);
GLOB_ERROR = retval;
diff --git a/ext/File-Glob/t/basic.t b/ext/File-Glob/t/basic.t
index b9d46b1142..3ea52d2cd6 100644
--- a/ext/File-Glob/t/basic.t
+++ b/ext/File-Glob/t/basic.t
@@ -15,7 +15,7 @@ BEGIN {
}
}
use strict;
-use Test::More tests => 14;
+use Test::More tests => 15;
BEGIN {use_ok('File::Glob', ':glob')};
use Cwd ();
@@ -195,3 +195,7 @@ pass("Don't panic");
local $TODO = "home-made glob doesn't do regexes" if $^O eq 'VMS';
is_deeply(\@glob_files, ['a_dej']);
}
+
+# This used to segfault.
+my $i = bsd_glob('*', GLOB_ALTDIRFUNC);
+is(&File::Glob::GLOB_ERROR, 0, "Successfuly ignored unsupported flag");