Skip to content

Commit 1ccc4ff

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix stack underflow in phar
2 parents 58339f3 + 7fb7869 commit 1ccc4ff

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

ext/phar/phar.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,27 +1832,24 @@ static int phar_analyze_path(const char *fname, const char *ext, int ext_len, in
18321832
/* check for ".phar" in extension */
18331833
static int phar_check_str(const char *fname, const char *ext_str, int ext_len, int executable, int for_create) /* {{{ */
18341834
{
1835-
char test[51];
18361835
const char *pos;
18371836

18381837
if (ext_len < 0 || ext_len >= 50) {
18391838
return FAILURE;
18401839
}
1841-
18421840
if (executable == 1) {
1843-
/* copy "." as well */
1844-
memcpy(test, ext_str - 1, ext_len + 1);
1845-
test[ext_len + 1] = '\0';
18461841
/* executable phars must contain ".phar" as a valid extension (phar://.pharmy/oops is invalid) */
18471842
/* (phar://hi/there/.phar/oops is also invalid) */
1848-
pos = strstr(test, ".phar");
1843+
pos = strstr(ext_str, ".phar");
18491844

1850-
if (pos && (*(pos - 1) != '/')
1851-
&& (pos += 5) && (*pos == '\0' || *pos == '/' || *pos == '.')) {
1852-
return phar_analyze_path(fname, ext_str, ext_len, for_create);
1853-
} else {
1845+
if (!pos
1846+
|| pos != ext_str && (*(pos - 1) == '/')
1847+
|| (ext_len - (pos - ext_str)) < 5
1848+
|| !(pos += 5)
1849+
|| !(*pos == '\0' || *pos == '/' || *pos == '.')) {
18541850
return FAILURE;
18551851
}
1852+
return phar_analyze_path(fname, ext_str, ext_len, for_create);
18561853
}
18571854

18581855
/* data phars need only contain a single non-"." to be valid */

0 commit comments

Comments
 (0)