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 15:04:16 -0500
commit1af4051e077438976a4c12a0622feaf6715bec77 (patch)
tree9db08b5d17655bfc661b5a56db78828af35c38b0
parent2417db0fb29c260ae01503cff9af78540eeb4198 (diff)
downloadperl-1af4051e077438976a4c12a0622feaf6715bec77.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 5231d0f37b..af17cffa76 100644
--- a/ext/File-Glob/Glob.pm
+++ b/ext/File-Glob/Glob.pm
@@ -36,7 +36,7 @@ use feature 'switch';
@EXPORT_OK = (@{$EXPORT_TAGS{'glob'}}, 'csh_glob');
-$VERSION = '1.12';
+$VERSION = '1.13';
sub import {
require Exporter;
diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
index 3f4928f934..5a08a0d079 100644
--- a/ext/File-Glob/Glob.xs
+++ b/ext/File-Glob/Glob.xs
@@ -57,11 +57,14 @@ 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);
} else if (ix) {
flags = (int) SvIV(get_sv("File::Glob::DEFAULT_FLAGS", GV_ADD));
}
/* 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 e3313807f1..ed8301900f 100644
--- a/ext/File-Glob/t/basic.t
+++ b/ext/File-Glob/t/basic.t
@@ -10,7 +10,7 @@ BEGIN {
}
}
use strict;
-use Test::More tests => 14;
+use Test::More tests => 15;
BEGIN {use_ok('File::Glob', ':glob')};
use Cwd ();
@@ -187,3 +187,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");