diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-11-24 22:44:27 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-11-24 22:44:27 +0000 |
commit | 38929bc06ae95e7e0c014c556a9752f7ef3d0371 (patch) | |
tree | a2f41b648ed273ef5fb5cd161a5cd1fe29cf2ca1 /src/backend/utils/adt/regexp.c | |
parent | a007dd1d21a161221e24350bd9343464a34e3c32 (diff) | |
download | postgresql-38929bc06ae95e7e0c014c556a9752f7ef3d0371.tar.gz postgresql-38929bc06ae95e7e0c014c556a9752f7ef3d0371.zip |
Our interface code for Spencer's regexp package was checking for regexp
error conditions during regexp compile, but not during regexp execution;
any sort of "can't happen" errors would be treated as no-match instead
of being reported as they should be. Noticed while trying to duplicate
a reported Tcl bug.
Diffstat (limited to 'src/backend/utils/adt/regexp.c')
-rw-r--r-- | src/backend/utils/adt/regexp.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index babafa0b980..2c60938e3f0 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.49.4.1 2004/02/03 17:56:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.49.4.2 2004/11/24 22:44:27 tgl Exp $ * * Alistair Crooks added the code for the regex caching * agc - cached the regular expressions used - there's a good chance @@ -106,6 +106,7 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, int regcomp_result; int regexec_result; cached_re_str re_temp; + char errMsg[100]; /* Convert data string to wide characters */ data = (pg_wchar *) palloc((dat_len + 1) * sizeof(pg_wchar)); @@ -143,7 +144,17 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, pfree(data); - return (regexec_result == 0); + if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH) + { + /* re failed??? */ + pg_regerror(regexec_result, &re_array[0].cre_re, + errMsg, sizeof(errMsg)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION), + errmsg("regular expression failed: %s", errMsg))); + } + + return (regexec_result == REG_OKAY); } } @@ -165,11 +176,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, pfree(pattern); - if (regcomp_result != 0) + if (regcomp_result != REG_OKAY) { /* re didn't compile */ - char errMsg[100]; - pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg)); /* XXX should we pg_regfree here? */ ereport(ERROR, @@ -221,7 +230,17 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, pfree(data); - return (regexec_result == 0); + if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH) + { + /* re failed??? */ + pg_regerror(regexec_result, &re_array[0].cre_re, + errMsg, sizeof(errMsg)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION), + errmsg("regular expression failed: %s", errMsg))); + } + + return (regexec_result == REG_OKAY); } |