Skip to content

Commit 236404f

Browse files
committed
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.
1 parent cf796cc commit 236404f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/backend/utils/adt/regexp.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.54 2004/08/29 04:12:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.55 2004/11/24 22:44:07 tgl Exp $
1212
*
1313
* Alistair Crooks added the code for the regex caching
1414
* agc - cached the regular expressions used - there's a good chance
@@ -107,6 +107,7 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
107107
int regcomp_result;
108108
int regexec_result;
109109
cached_re_str re_temp;
110+
char errMsg[100];
110111

111112
/* Convert data string to wide characters */
112113
data = (pg_wchar *) palloc((dat_len + 1) * sizeof(pg_wchar));
@@ -144,7 +145,17 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
144145

145146
pfree(data);
146147

147-
return (regexec_result == 0);
148+
if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH)
149+
{
150+
/* re failed??? */
151+
pg_regerror(regexec_result, &re_array[0].cre_re,
152+
errMsg, sizeof(errMsg));
153+
ereport(ERROR,
154+
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
155+
errmsg("regular expression failed: %s", errMsg)));
156+
}
157+
158+
return (regexec_result == REG_OKAY);
148159
}
149160
}
150161

@@ -166,11 +177,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
166177

167178
pfree(pattern);
168179

169-
if (regcomp_result != 0)
180+
if (regcomp_result != REG_OKAY)
170181
{
171182
/* re didn't compile */
172-
char errMsg[100];
173-
174183
pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
175184
/* XXX should we pg_regfree here? */
176185
ereport(ERROR,
@@ -222,7 +231,17 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
222231

223232
pfree(data);
224233

225-
return (regexec_result == 0);
234+
if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH)
235+
{
236+
/* re failed??? */
237+
pg_regerror(regexec_result, &re_array[0].cre_re,
238+
errMsg, sizeof(errMsg));
239+
ereport(ERROR,
240+
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
241+
errmsg("regular expression failed: %s", errMsg)));
242+
}
243+
244+
return (regexec_result == REG_OKAY);
226245
}
227246

228247

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy