]> granicus.if.org Git - php/commitdiff
Applied fix for #17764.
authorAndrei Zmievski <andrei@php.net>
Mon, 17 Jun 2002 15:10:22 +0000 (15:10 +0000)
committerAndrei Zmievski <andrei@php.net>
Mon, 17 Jun 2002 15:10:22 +0000 (15:10 +0000)
@- Fixed a crash in ereg_replace() when backreference number was greater
@  than the number of subpatterns. (oliver@billix.franken.de)

ext/ereg/ereg.c
ext/standard/reg.c

index 0335347b396521ea404825567cc44e37b83958d0..13e06ba3cc630f3d57256bab0ef2baabab13473c 100644 (file)
@@ -342,6 +342,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                        while (*walk)
                                if ('\\' == *walk
                                        && '0' <= walk[1] && '9' >= walk[1]
+                                       && walk[1] - '0' <= re.re_nsub
                                        && subs[walk[1] - '0'].rm_so > -1
                                        && subs[walk[1] - '0'].rm_eo > -1) {
                                        new_l += subs[walk[1] - '0'].rm_eo
@@ -369,6 +370,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                        while (*walk)
                                if ('\\' == *walk
                                        && '0' <= walk[1] && '9' >= walk[1]
+                                       && walk[1] - '0' <= re.re_nsub
                                        && subs[walk[1] - '0'].rm_so > -1
                                        && subs[walk[1] - '0'].rm_eo > -1
                                        /* this next case shouldn't happen. it does. */
index 0335347b396521ea404825567cc44e37b83958d0..13e06ba3cc630f3d57256bab0ef2baabab13473c 100644 (file)
@@ -342,6 +342,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                        while (*walk)
                                if ('\\' == *walk
                                        && '0' <= walk[1] && '9' >= walk[1]
+                                       && walk[1] - '0' <= re.re_nsub
                                        && subs[walk[1] - '0'].rm_so > -1
                                        && subs[walk[1] - '0'].rm_eo > -1) {
                                        new_l += subs[walk[1] - '0'].rm_eo
@@ -369,6 +370,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                        while (*walk)
                                if ('\\' == *walk
                                        && '0' <= walk[1] && '9' >= walk[1]
+                                       && walk[1] - '0' <= re.re_nsub
                                        && subs[walk[1] - '0'].rm_so > -1
                                        && subs[walk[1] - '0'].rm_eo > -1
                                        /* this next case shouldn't happen. it does. */