Add missing error check in regexp parser.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 27 Feb 2013 15:40:20 +0000 (10:40 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 27 Feb 2013 15:40:20 +0000 (10:40 -0500)
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.

src/backend/regex/regcomp.c

index 715d9fac4de0f6b2acd63bc767a9d534aa572065..17e7ce2ea548bfc97d0db1d92175f18bbff33969 100644 (file)
@@ -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)
@@ -1148,6 +1149,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);