@@ -1592,35 +1592,6 @@ zend_result phar_open_from_filename(char *fname, size_t fname_len, char *alias,
15921592}
15931593/* }}}*/
15941594
1595- static inline char * phar_strnstr (const char * buf , size_t buf_len , const char * search , size_t search_len ) /* {{{ */
1596- {
1597- const char * c ;
1598- ptrdiff_t so_far = 0 ;
1599-
1600- if (buf_len < search_len ) {
1601- return NULL ;
1602- }
1603-
1604- c = buf - 1 ;
1605-
1606- do {
1607- if (!(c = memchr (c + 1 , search [0 ], buf_len - search_len - so_far ))) {
1608- return (char * ) NULL ;
1609- }
1610-
1611- so_far = c - buf ;
1612-
1613- if (so_far >= (buf_len - search_len )) {
1614- return (char * ) NULL ;
1615- }
1616-
1617- if (!memcmp (c , search , search_len )) {
1618- return (char * ) c ;
1619- }
1620- } while (1 );
1621- }
1622- /* }}} */
1623-
16241595/**
16251596 * Scan an open fp for the required __HALT_COMPILER(); ?> token and verify
16261597 * that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS
@@ -1632,7 +1603,8 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16321603 static const char zip_magic [] = "PK\x03\x04" ;
16331604 static const char gz_magic [] = "\x1f\x8b\x08" ;
16341605 static const char bz_magic [] = "BZh" ;
1635- char * pos , test = '\0' ;
1606+ const char * pos ;
1607+ char test = '\0' ;
16361608 int recursion_count = 3 ; // arbitrary limit to avoid too deep or even infinite recursion
16371609 const int window_size = 1024 ;
16381610 char buffer [1024 + sizeof (token )]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1781,14 +1753,14 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
17811753 }
17821754
17831755 if (got >= 512 ) {
1784- if (phar_is_tar (pos , fname )) {
1756+ if (phar_is_tar (( char * ) pos , fname )) { /* TODO: fix const correctness */
17851757 php_stream_rewind (fp );
17861758 return phar_parse_tarfile (fp , fname , fname_len , alias , alias_len , pphar , compression , error );
17871759 }
17881760 }
17891761 }
17901762
1791- if (got > 0 && (pos = phar_strnstr (buffer , got + sizeof ( token ), token , sizeof (token )- 1 )) != NULL ) {
1763+ if (got > 0 && (pos = php_memnistr (buffer , token , tokenlen , buffer + got + sizeof (token ))) != NULL ) {
17921764 halt_offset += (pos - buffer ); /* no -tokenlen+tokenlen here */
17931765 return phar_parse_pharfile (fp , fname , fname_len , alias , alias_len , halt_offset , pphar , compression , error );
17941766 }
0 commit comments