Skip to content

Commit 1c24911

Browse files
committed
- Fixed bug #54681 (addGlob() crashes on invalid flags)
1 parent 1bf6d03 commit 1c24911

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

ext/zip/php_zip.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,28 @@ static char * php_zipobj_get_zip_comment(struct zip *za, int *len TSRMLS_DC) /*
493493
#else
494494
#define GLOB_FLAGMASK (~0)
495495
#endif
496+
#ifndef GLOB_BRACE
497+
# define GLOB_BRACE 0
498+
#endif
499+
#ifndef GLOB_MARK
500+
# define GLOB_MARK 0
501+
#endif
502+
#ifndef GLOB_NOSORT
503+
# define GLOB_NOSORT 0
504+
#endif
505+
#ifndef GLOB_NOCHECK
506+
# define GLOB_NOCHECK 0
507+
#endif
508+
#ifndef GLOB_NOESCAPE
509+
# define GLOB_NOESCAPE 0
510+
#endif
511+
#ifndef GLOB_ERR
512+
# define GLOB_ERR 0
513+
#endif
514+
515+
/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
516+
#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
517+
496518
#endif /* }}} */
497519

498520
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
507529
glob_t globbuf;
508530
int n;
509531
int ret;
532+
533+
if (pattern_len >= MAXPATHLEN) {
534+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
535+
return -1;
536+
}
537+
538+
if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
539+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
540+
return -1;
541+
}
510542

511543
#ifdef ZTS
512544
if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {

0 commit comments

Comments
 (0)