summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2013-02-27 15:40:26 +0000
committerTom Lane2013-02-27 15:40:26 +0000
commit4aa15467264caf118614827b25db260ec85438ba (patch)
treeaee94f9751e160ff6b38eeec3845aa9ff1756dda
parent4fd25a367f24b2bb374393db7c53e4f048ff6bf2 (diff)
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.
-rw-r--r--src/backend/regex/regcomp.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c
index c3e7588c053..1c4ac7c4000 100644
--- a/src/backend/regex/regcomp.c
+++ b/src/backend/regex/regcomp.c
@@ -704,6 +704,7 @@ parsebranch(struct vars * v,
/* NB, recursion in parseqatom() may swallow rest of branch */
parseqatom(v, stopper, type, lp, right, t);
+ NOERRN();
}
if (!seencontent)
@@ -1138,6 +1139,7 @@ parseqatom(struct vars * v,
EMPTYARC(atom->end, rp);
t->right = subre(v, '=', 0, atom->end, rp);
}
+ NOERR();
assert(SEE('|') || SEE(stopper) || SEE(EOS));
t->flags |= COMBINE(t->flags, t->right->flags);
top->flags |= COMBINE(top->flags, t->flags);