@@ -1590,35 +1590,6 @@ int phar_open_from_filename(char *fname, size_t fname_len, char *alias, size_t a
15901590}
15911591/* }}}*/
15921592
1593- static inline char * phar_strnstr (const char * buf , size_t buf_len , const char * search , size_t search_len ) /* {{{ */
1594- {
1595- const char * c ;
1596- ptrdiff_t so_far = 0 ;
1597-
1598- if (buf_len < search_len ) {
1599- return NULL ;
1600- }
1601-
1602- c = buf - 1 ;
1603-
1604- do {
1605- if (!(c = memchr (c + 1 , search [0 ], buf_len - search_len - so_far ))) {
1606- return (char * ) NULL ;
1607- }
1608-
1609- so_far = c - buf ;
1610-
1611- if (so_far >= (buf_len - search_len )) {
1612- return (char * ) NULL ;
1613- }
1614-
1615- if (!memcmp (c , search , search_len )) {
1616- return (char * ) c ;
1617- }
1618- } while (1 );
1619- }
1620- /* }}} */
1621-
16221593/**
16231594 * Scan an open fp for the required __HALT_COMPILER(); ?> token and verify
16241595 * that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS
@@ -1630,7 +1601,8 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16301601 static const char zip_magic [] = "PK\x03\x04" ;
16311602 static const char gz_magic [] = "\x1f\x8b\x08" ;
16321603 static const char bz_magic [] = "BZh" ;
1633- char * pos , test = '\0' ;
1604+ const char * pos ;
1605+ char test = '\0' ;
16341606 int recursion_count = 3 ; // arbitrary limit to avoid too deep or even infinite recursion
16351607 const int window_size = 1024 ;
16361608 char buffer [1024 + sizeof (token )]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1779,14 +1751,14 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17791751 }
17801752
17811753 if (got >= 512 ) {
1782- if (phar_is_tar (pos , fname )) {
1754+ if (phar_is_tar (( char * ) pos , fname )) { /* TODO: fix const correctness */
17831755 php_stream_rewind (fp );
17841756 return phar_parse_tarfile (fp , fname , fname_len , alias , alias_len , pphar , is_data , compression , error );
17851757 }
17861758 }
17871759 }
17881760
1789- if (got > 0 && (pos = phar_strnstr (buffer , got + sizeof ( token ), token , sizeof (token )- 1 )) != NULL ) {
1761+ if (got > 0 && (pos = php_memnistr (buffer , token , tokenlen , buffer + got + sizeof (token ))) != NULL ) {
17901762 halt_offset += (pos - buffer ); /* no -tokenlen+tokenlen here */
17911763 return phar_parse_pharfile (fp , fname , fname_len , alias , alias_len , halt_offset , pphar , compression , error );
17921764 }
0 commit comments