diff options
author | Craig A. Berry <craigberry@mac.com> | 2011-08-19 10:14:13 -0500 |
---|---|---|
committer | Craig A. Berry <craigberry@mac.com> | 2011-09-03 07:58:32 -0500 |
commit | 3c97495f56fb647c187ea86b3486f83e2a360144 (patch) | |
tree | 55193c4fd15a041013905c589e113f6eb561ae61 /ext/File-Glob | |
parent | 457f72034425ae46e400ba8bc323faeac268c51f (diff) | |
download | perl-3c97495f56fb647c187ea86b3486f83e2a360144.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>.
Diffstat (limited to 'ext/File-Glob')
-rw-r--r-- | ext/File-Glob/Glob.pm | 2 | ||||
-rw-r--r-- | ext/File-Glob/Glob.xs | 3 | ||||
-rw-r--r-- | ext/File-Glob/t/basic.t | 6 |
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"); |