Blob Blame History Raw
From 1af4051e077438976a4c12a0622feaf6715bec77 Mon Sep 17 00:00:00 2001
From: "Craig A. Berry" <craigberry@mac.com>
Date: Fri, 19 Aug 2011 10:14:13 -0500
Subject: [PATCH] Plug segfault in bsd_glob() with unsupported ALTDIRFUNC
 flag.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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>.

Petr Pisar: Version bump removed and rebased for Perl 5.12.4.
---
 ext/File-Glob/Glob.xs   |    3 +++
 ext/File-Glob/t/basic.t |    6 +++++-

diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
index 3f4928f..5a08a0d 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 e331380..ed83019 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");
-- 
1.7.6.4