Fix seg fault handling template parameter expressions containing '<='

Recent commits ensure types are correctly stored in SwigType *. In
particular template parameters are enclosed within '<(' and ')>'.
Now we can confidently handle template parameters as really being
delimited as such to fix an infinite loop handling template expressions
containing '<' or '>'. The previous implementation only assumed
template parameters were delimited by '<' and '>'.

Issue #1037
This commit is contained in:
William S Fulton 2022-11-22 08:30:39 +00:00
commit 0341258af7
3 changed files with 24 additions and 5 deletions

View file

@ -1234,17 +1234,20 @@ String *SwigType_prefix(const SwigType *t) {
while (d > c) {
d--;
if (*d == '>') {
if (*d == '>' && (d > c) && *(d - 1) == ')') {
/* skip over template parameters */
int nest = 1;
d--;
d--;
while ((d > c) && (nest)) {
if (*d == '>')
if (*d == '>' && *(d - 1) == ')')
nest++;
if (*d == '<')
if (*d == '<' && *(d + 1) == '(')
nest--;
d--;
}
}
if (*d == ')') {
/* Skip over params */
int nparen = 1;
@ -1259,10 +1262,10 @@ String *SwigType_prefix(const SwigType *t) {
}
if (*d == '.') {
char t = *(d + 1);
char x = *(d + 1);
*(d + 1) = 0;
r = NewString(c);
*(d + 1) = t;
*(d + 1) = x;
return r;
}
}