Fix crash when requesting more matches than available in regex
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12904 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7c58a044d2
commit
29fd1e3ce4
2 changed files with 15 additions and 8 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.5 (in progress)
|
Version 2.0.5 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2012-01-24: wsfulton
|
||||||
|
Fix crash with bad regex - bug #3474250.
|
||||||
|
|
||||||
2012-01-24: wsfulton
|
2012-01-24: wsfulton
|
||||||
[Python] Add Python stepped slicing support to the STL wrappers (std::vector, std::list).
|
[Python] Add Python stepped slicing support to the STL wrappers (std::vector, std::list).
|
||||||
Assigning to a slice, reading a slice and deleting a slice with steps now work.
|
Assigning to a slice, reading a slice and deleting a slice with steps now work.
|
||||||
|
|
|
||||||
|
|
@ -1147,7 +1147,7 @@ err_out:
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String *replace_captures(const char *input, String *subst, int captures[])
|
String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s)
|
||||||
{
|
{
|
||||||
String *result = NewStringEmpty();
|
String *result = NewStringEmpty();
|
||||||
const char *p = Char(subst);
|
const char *p = Char(subst);
|
||||||
|
|
@ -1167,9 +1167,14 @@ String *replace_captures(const char *input, String *subst, int captures[])
|
||||||
Putc('\\', result);
|
Putc('\\', result);
|
||||||
} else if (isdigit((unsigned char)*p)) {
|
} else if (isdigit((unsigned char)*p)) {
|
||||||
int group = *p++ - '0';
|
int group = *p++ - '0';
|
||||||
int l = captures[group*2], r = captures[group*2 + 1];
|
if (group < num_captures) {
|
||||||
if (l != -1) {
|
int l = captures[group*2], r = captures[group*2 + 1];
|
||||||
Write(result, input + l, r - l);
|
if (l != -1) {
|
||||||
|
Write(result, input + l, r - l);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Swig_error("SWIG", Getline(s), "PCRE capture replacement failed while matching \"%s\" using \"%s\" - request for group %d is greater than the number of captures %d.\n",
|
||||||
|
Char(pattern), input, group, num_captures-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1206,10 +1211,9 @@ String *Swig_string_regex(String *s) {
|
||||||
}
|
}
|
||||||
rc = pcre_exec(compiled_pat, NULL, input, strlen(input), 0, 0, captures, 30);
|
rc = pcre_exec(compiled_pat, NULL, input, strlen(input), 0, 0, captures, 30);
|
||||||
if (rc >= 0) {
|
if (rc >= 0) {
|
||||||
res = replace_captures(input, subst, captures);
|
res = replace_captures(rc, input, subst, captures, pattern, s);
|
||||||
}
|
} else if (rc != PCRE_ERROR_NOMATCH) {
|
||||||
else if (rc != PCRE_ERROR_NOMATCH) {
|
Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" using \"%s\".\n",
|
||||||
Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" in \"%s\".\n",
|
|
||||||
rc, Char(pattern), input);
|
rc, Char(pattern), input);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue