summaryrefslogtreecommitdiff
path: root/ext/zip
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2011-05-07 01:58:26 +0000
committerFelipe Pena <felipe@php.net>2011-05-07 01:58:26 +0000
commit1c24911a46c6c8b2675e40494ebd50a321d60e69 (patch)
treebbed1db195e7b678e691ed98ef64f0d37f8f3eb1 /ext/zip
parent1bf6d03020b8b89bbb3899aa7145a622702b7548 (diff)
downloadphp-git-1c24911a46c6c8b2675e40494ebd50a321d60e69.tar.gz
- Fixed bug #54681 (addGlob() crashes on invalid flags)
Diffstat (limited to 'ext/zip')
-rw-r--r--ext/zip/php_zip.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index c51d2f6aeb..56abd80beb 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -493,6 +493,28 @@ static char * php_zipobj_get_zip_comment(struct zip *za, int *len TSRMLS_DC) /*
#else
#define GLOB_FLAGMASK (~0)
#endif
+#ifndef GLOB_BRACE
+# define GLOB_BRACE 0
+#endif
+#ifndef GLOB_MARK
+# define GLOB_MARK 0
+#endif
+#ifndef GLOB_NOSORT
+# define GLOB_NOSORT 0
+#endif
+#ifndef GLOB_NOCHECK
+# define GLOB_NOCHECK 0
+#endif
+#ifndef GLOB_NOESCAPE
+# define GLOB_NOESCAPE 0
+#endif
+#ifndef GLOB_ERR
+# define GLOB_ERR 0
+#endif
+
+/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
+#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
+
#endif /* }}} */
int php_zip_glob(char *pattern, int pattern_len, long flags, zval *return_value TSRMLS_DC) /* {{{ */
@@ -507,6 +529,16 @@ int php_zip_glob(char *pattern, int pattern_len, long flags, zval *return_value
glob_t globbuf;
int n;
int ret;
+
+ if (pattern_len >= MAXPATHLEN) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
+ return -1;
+ }
+
+ if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
+ return -1;
+ }
#ifdef ZTS
if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {