Skip to content

Commit 0c54796

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 c191ec7 commit 0c54796

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
@@ -704,6 +704,7 @@ parsebranch(struct vars * v,
704704

705705
/* NB, recursion in parseqatom() may swallow rest of branch */
706706
parseqatom(v, stopper, type, lp, right, t);
707+
NOERRN();
707708
}
708709

709710
if (!seencontent)
@@ -1148,6 +1149,7 @@ parseqatom(struct vars * v,
11481149
EMPTYARC(atom->end, rp);
11491150
t->right = subre(v, '=', 0, atom->end, rp);
11501151
}
1152+
NOERR();
11511153
assert(SEE('|') || SEE(stopper) || SEE(EOS));
11521154
t->flags |= COMBINE(t->flags, t->right->flags);
11531155
top->flags |= COMBINE(top->flags, t->flags);

0 commit comments

Comments
 (0)