andrei Tue Jun 22 18:20:39 2004 EDT
Modified files: (Branch: PHP_4_3)
/php-src NEWS
/php-src/ext/pcre php_pcre.c
Log:
pcre_info() is deprecated. Hence, update to pcre_fullinfo() and do more
rigorous checking of return values.
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1247.2.685&r2=1.1247.2.686&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1247.2.685 php-src/NEWS:1.1247.2.686
--- php-src/NEWS:1.1247.2.685 Tue Jun 22 11:55:05 2004
+++ php-src/NEWS Tue Jun 22 18:20:38 2004
@@ -1,6 +1,7 @@
PHP 4 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2004, Version 4.3.8
+- Updated PCRE to provide better error handling in certain cases. (Andrei)
- Fixed bug #28868 (Internal wrapper registry not thread safe). (Sara)
- Fixed bug #28818 (Apache 2 sapis do not export st_dev).
(xuefer at 21cn dot com, Ilia).
http://cvs.php.net/diff.php/php-src/ext/pcre/php_pcre.c?r1=1.132.2.17&r2=1.132.2.18&ty=u
Index: php-src/ext/pcre/php_pcre.c
diff -u php-src/ext/pcre/php_pcre.c:1.132.2.17 php-src/ext/pcre/php_pcre.c:1.132.2.18
--- php-src/ext/pcre/php_pcre.c:1.132.2.17 Fri Apr 23 13:51:39 2004
+++ php-src/ext/pcre/php_pcre.c Tue Jun 22 18:20:38 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.132.2.17 2004/04/23 17:51:39 rasmus Exp $ */
+/* $Id: php_pcre.c,v 1.132.2.18 2004/06/22 22:20:38 andrei Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -347,7 +347,7 @@
const char **stringlist; /* Holds list of subpatterns */
char *match; /* The current match */
char **subpat_names = NULL;/* Array for named subpatterns */
- int i;
+ int i, rc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ((global) ? "ssz|ll" :
"ss|zll"), ®ex, ®ex_len,
&subject, &subject_len,
&subpats, &flags, &start_offset) == FAILURE) {
@@ -393,7 +393,12 @@
}
/* Calculate the size of the offsets array, and allocate memory for it. */
- pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats);
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats);
+ if (rc < 0) {
+ php_error(E_WARNING, "%s: internal pcre_fullinfo() error %d",
+ get_active_function_name(TSRMLS_C), rc);
+ RETURN_FALSE;
+ }
num_subpats++;
size_offsets = num_subpats * 3;
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
@@ -410,10 +415,22 @@
char *name_table;
unsigned short name_idx;
- pcre_fullinfo(re, extra, PCRE_INFO_NAMECOUNT, &name_cnt);
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_NAMECOUNT, &name_cnt);
+ if (rc < 0) {
+ php_error(E_WARNING, "%s: internal pcre_fullinfo() error %d",
+ get_active_function_name(TSRMLS_C), rc);
+ RETURN_FALSE;
+ }
if (name_cnt > 0) {
- pcre_fullinfo(re, extra, PCRE_INFO_NAMETABLE, &name_table);
- pcre_fullinfo(re, extra, PCRE_INFO_NAMEENTRYSIZE, &name_size);
+ int rc1, rc2;
+ rc1 = pcre_fullinfo(re, extra, PCRE_INFO_NAMETABLE,
&name_table);
+ rc2 = pcre_fullinfo(re, extra, PCRE_INFO_NAMEENTRYSIZE,
&name_size);
+ rc = rc2 ? rc2 : rc1;
+ if (rc < 0) {
+ php_error(E_WARNING, "%s: internal pcre_fullinfo()
error %d",
+ get_active_function_name(TSRMLS_C),
rc);
+ RETURN_FALSE;
+ }
while (ni++ < name_cnt) {
name_idx = 0xff * name_table[0] + name_table[1];
@@ -782,6 +799,7 @@
*replace_end=NULL, /* End of replacement
string */
*eval_result, /* Result of eval or
custom function */
walk_last; /* Last walked
character */
+ int rc;
/* Compile regex or get it from cache. */
if ((re = pcre_get_compiled_regex(regex, &extra, &preg_options)) == NULL) {
@@ -801,7 +819,13 @@
}
/* Calculate the size of the offsets array, and allocate memory for it. */
- size_offsets = (pcre_info(re, NULL, NULL) + 1) * 3;
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &size_offsets);
+ if (rc < 0) {
+ php_error(E_WARNING, "%s: internal pcre_fullinfo() error %d",
+ get_active_function_name(TSRMLS_C), rc);
+ return NULL;
+ }
+ size_offsets = (size_offsets + 1) * 3;
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
alloc_len = 2 * subject_len + 1;
@@ -1165,6 +1189,7 @@
int g_notempty = 0; /* If the match should
not be empty */
char *match, /* The current match */
*last_match; /* Location of last
match */
+ int rc;
/* Get function parameters and do error checking */
argc = ZEND_NUM_ARGS();
@@ -1199,7 +1224,13 @@
array_init(return_value);
/* Calculate the size of the offsets array, and allocate memory for it. */
- size_offsets = (pcre_info(re, NULL, NULL) + 1) * 3;
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &size_offsets);
+ if (rc < 0) {
+ php_error(E_WARNING, "%s: internal pcre_fullinfo() error %d",
+ get_active_function_name(TSRMLS_C), rc);
+ RETURN_FALSE;
+ }
+ size_offsets = (size_offsets + 1) * 3;
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
/* Start at the beginning of the string */
@@ -1406,6 +1437,7 @@
ulong num_key;
zend_bool invert = 0; /* Whether to return
non-matching
entries */
+ int rc;
/* Get arguments and do error checking */
@@ -1435,7 +1467,13 @@
}
/* Calculate the size of the offsets array, and allocate memory for it. */
- size_offsets = (pcre_info(re, NULL, NULL) + 1) * 3;
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &size_offsets);
+ if (rc < 0) {
+ php_error(E_WARNING, "%s: internal pcre_fullinfo() error %d",
+ get_active_function_name(TSRMLS_C), rc);
+ RETURN_FALSE;
+ }
+ size_offsets = (size_offsets + 1) * 3;
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
/* Initialize return array */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php