Re: [PHP-CVS] cvs: php-src(PHP_5_2) /ext/pcre php_pcre.c /ext/pcre/tests bug37911.phpt
Sorry, I have accidentally committed without log. This is a MFB of the fix for #37911 which had been fixed in 5.3 but not in 5.2, fixes #45748. On Friday 08 August 2008 11:34:08 Arnaud Le Blanc wrote: lbarnaud Fri Aug 8 09:34:08 2008 UTC Added files: (Branch: PHP_5_2) /php-src/ext/pcre/tests bug37911.phpt Modified files: /php-src/ext/pcre php_pcre.c Log: http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/php_pcre.c?r1=1.168.2.9.2.25 r2=1.168.2.9.2.26diff_format=u Index: php-src/ext/pcre/php_pcre.c diff -u php-src/ext/pcre/php_pcre.c:1.168.2.9.2.25 php-src/ext/pcre/php_pcre.c:1.168.2.9.2.26 --- php-src/ext/pcre/php_pcre.c:1.168.2.9.2.25Wed Feb 20 22:08:18 2008 +++ php-src/ext/pcre/php_pcre.c Fri Aug 8 09:34:08 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_pcre.c,v 1.168.2.9.2.25 2008/02/20 22:08:18 felipe Exp $ */ +/* $Id: php_pcre.c,v 1.168.2.9.2.26 2008/08/08 09:34:08 lbarnaud Exp $ */ #include php.h #include php_ini.h @@ -174,6 +174,50 @@ } /* }}} */ +/* {{{ static make_subpats_table */ +static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_DC) +{ + pcre_extra *extra = pce-extra; + int name_cnt = 0, name_size, ni = 0; + int rc; + char *name_table; + unsigned short name_idx; + char **subpat_names = (char **)ecalloc(num_subpats, sizeof(char *)); + + rc = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMECOUNT, name_cnt); + if (rc 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Internal pcre_fullinfo() error %d, rc); + efree(subpat_names); + return NULL; + } + if (name_cnt 0) { + int rc1, rc2; + + rc1 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMETABLE, name_table); + rc2 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMEENTRYSIZE, name_size); +rc = rc2 ? rc2 : rc1; + if (rc 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Internal pcre_fullinfo() error %d, rc); + efree(subpat_names); + return NULL; + } + + while (ni++ name_cnt) { + name_idx = 0xff * name_table[0] + name_table[1]; + subpat_names[name_idx] = name_table + 2; + if (is_numeric_string(subpat_names[name_idx], strlen(subpat_names[name_idx]), NULL, NULL, 0) 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Numeric named subpatterns are not allowed); + efree(subpat_names); + return NULL; + } + name_table += name_size; + } + } + + return subpat_names; +} +/* }}} */ + /* {{{ pcre_get_compiled_regex_cache */ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) @@ -484,7 +528,7 @@ int g_notempty = 0;/* If the match should not be empty */ const char **stringlist;/* Holds list of subpatterns */ char*match; /* The current match */ - char **subpat_names = NULL;/* Array for named subpatterns */ + char **subpat_names; /* Array for named subpatterns */ int i, rc; int subpats_order; /* Order of subpattern matches */ int offset_capture;/* Capture match offsets: yes/no */ @@ -539,54 +583,19 @@ } num_subpats++; size_offsets = num_subpats * 3; - offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0); /* * Build a mapping from subpattern numbers to their names. We will always * allocate the table, even though there may be no named subpatterns. This * avoids somewhat more complicated logic in the inner loops. */ - subpat_names = (char **)safe_emalloc(num_subpats, sizeof(char *), 0); - memset(subpat_names, 0, sizeof(char *) * num_subpats); - { - int name_cnt = 0, name_size, ni = 0; - char *name_table; - unsigned short name_idx; - - rc = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMECOUNT, name_cnt); - if (rc 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, Internal pcre_fullinfo() error %d, rc); - efree(offsets); - efree(subpat_names); - RETURN_FALSE; - } - if (name_cnt 0) { - int rc1, rc2; - - rc1 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMETABLE, name_table); -
[PHP-CVS] cvs: php-src(PHP_5_2) /ext/pcre php_pcre.c /ext/pcre/tests bug37911.phpt
lbarnaudFri Aug 8 09:34:08 2008 UTC Added files: (Branch: PHP_5_2) /php-src/ext/pcre/tests bug37911.phpt Modified files: /php-src/ext/pcre php_pcre.c Log: http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/php_pcre.c?r1=1.168.2.9.2.25r2=1.168.2.9.2.26diff_format=u Index: php-src/ext/pcre/php_pcre.c diff -u php-src/ext/pcre/php_pcre.c:1.168.2.9.2.25 php-src/ext/pcre/php_pcre.c:1.168.2.9.2.26 --- php-src/ext/pcre/php_pcre.c:1.168.2.9.2.25 Wed Feb 20 22:08:18 2008 +++ php-src/ext/pcre/php_pcre.c Fri Aug 8 09:34:08 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_pcre.c,v 1.168.2.9.2.25 2008/02/20 22:08:18 felipe Exp $ */ +/* $Id: php_pcre.c,v 1.168.2.9.2.26 2008/08/08 09:34:08 lbarnaud Exp $ */ #include php.h #include php_ini.h @@ -174,6 +174,50 @@ } /* }}} */ +/* {{{ static make_subpats_table */ +static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_DC) +{ + pcre_extra *extra = pce-extra; + int name_cnt = 0, name_size, ni = 0; + int rc; + char *name_table; + unsigned short name_idx; + char **subpat_names = (char **)ecalloc(num_subpats, sizeof(char *)); + + rc = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMECOUNT, name_cnt); + if (rc 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Internal pcre_fullinfo() error %d, rc); + efree(subpat_names); + return NULL; + } + if (name_cnt 0) { + int rc1, rc2; + + rc1 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMETABLE, name_table); + rc2 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMEENTRYSIZE, name_size); + rc = rc2 ? rc2 : rc1; + if (rc 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Internal pcre_fullinfo() error %d, rc); + efree(subpat_names); + return NULL; + } + + while (ni++ name_cnt) { + name_idx = 0xff * name_table[0] + name_table[1]; + subpat_names[name_idx] = name_table + 2; + if (is_numeric_string(subpat_names[name_idx], strlen(subpat_names[name_idx]), NULL, NULL, 0) 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Numeric named subpatterns are not allowed); + efree(subpat_names); + return NULL; + } + name_table += name_size; + } + } + + return subpat_names; +} +/* }}} */ + /* {{{ pcre_get_compiled_regex_cache */ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) @@ -484,7 +528,7 @@ int g_notempty = 0;/* If the match should not be empty */ const char **stringlist;/* Holds list of subpatterns */ char*match; /* The current match */ - char **subpat_names = NULL;/* Array for named subpatterns */ + char **subpat_names; /* Array for named subpatterns */ int i, rc; int subpats_order; /* Order of subpattern matches */ int offset_capture;/* Capture match offsets: yes/no */ @@ -539,54 +583,19 @@ } num_subpats++; size_offsets = num_subpats * 3; - offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0); /* * Build a mapping from subpattern numbers to their names. We will always * allocate the table, even though there may be no named subpatterns. This * avoids somewhat more complicated logic in the inner loops. */ - subpat_names = (char **)safe_emalloc(num_subpats, sizeof(char *), 0); - memset(subpat_names, 0, sizeof(char *) * num_subpats); - { - int name_cnt = 0, name_size, ni = 0; - char *name_table; - unsigned short name_idx; - - rc = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMECOUNT, name_cnt); - if (rc 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, Internal pcre_fullinfo() error %d, rc); - efree(offsets); - efree(subpat_names); - RETURN_FALSE; - } - if (name_cnt 0) { - int rc1, rc2; - - rc1 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMETABLE, name_table); - rc2 = pcre_fullinfo(pce-re, extra, PCRE_INFO_NAMEENTRYSIZE, name_size); - rc = rc2 ? rc2 : rc1; -