Skip to content

Commit f5185db

Browse files
committed
Add missing error check in regexp parser.
parseqatom() failed to check for an error return (NULL result) from its recursive call to parsebranch(), and in consequence could crash with a null-pointer dereference after an error return. This bug has been there since day one, but wasn't noticed before, probably because most error cases in parsebranch() didn't actually lead to returning NULL. Add the missing error check, and also tweak parsebranch() to exit in a less indirect fashion after a call to parseqatom() fails. Report by Tomasz Karlik, fix by me.
1 parent bd0bfe1 commit f5185db

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/backend/regex/regcomp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ parsebranch(struct vars * v,
711711

712712
/* NB, recursion in parseqatom() may swallow rest of branch */
713713
parseqatom(v, stopper, type, lp, right, t);
714+
NOERRN();
714715
}
715716

716717
if (!seencontent)
@@ -1155,6 +1156,7 @@ parseqatom(struct vars * v,
11551156
EMPTYARC(atom->end, rp);
11561157
t->right = subre(v, '=', 0, atom->end, rp);
11571158
}
1159+
NOERR();
11581160
assert(SEE('|') || SEE(stopper) || SEE(EOS));
11591161
t->flags |= COMBINE(t->flags, t->right->flags);
11601162
top->flags |= COMBINE(top->flags, t->flags);

0 commit comments

Comments
 (0)