]> granicus.if.org Git - php/commitdiff
MFH: fix bug #47662: support more than 127 named subpatterns
authorNuno Lopes <nlopess@php.net>
Tue, 14 Apr 2009 20:31:32 +0000 (20:31 +0000)
committerNuno Lopes <nlopess@php.net>
Tue, 14 Apr 2009 20:31:32 +0000 (20:31 +0000)
ext/pcre/php_pcre.c
ext/pcre/tests/bug47662.phpt [new file with mode: 0644]

index b412eb9f399c35e31390cfb86282ca7fc2b0485c..bcf9c425fa41d6c36dcb3d47efef8a68ef8f63ab 100644 (file)
@@ -209,7 +209,7 @@ static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_D
                }
 
                while (ni++ < name_cnt) {
-                       name_idx = 0xff * name_table[0] + name_table[1];
+                       name_idx = 0xff * (unsigned char)name_table[0] + (unsigned char)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");
diff --git a/ext/pcre/tests/bug47662.phpt b/ext/pcre/tests/bug47662.phpt
new file mode 100644 (file)
index 0000000..d605674
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #47662 (support more than 127 named subpatterns)
+--FILE--
+<?php
+
+$regex = '@';
+for($bar=0; $bar<1027; $bar++) {
+       $regex .= '((?P<x'.$bar.'>))';
+}
+$regex .= 'fo+bar@';
+
+var_dump(preg_match($regex, 'foobar'));
+echo "Done!\n";
+
+?>
+--EXPECT--
+int(1)
+Done!