Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54fd196

Browse files
committed
Prevent corner-case core dump in rfree().
rfree() failed to cope with the case that pg_regcomp() had initialized theregex_t struct but then failed to allocate any memory for re->re_guts (ie,the first malloc call in pg_regcomp() failed). It would try to touch theguts struct anyway, and thus dump core. This is a sufficiently narrowcorner case that it's not surprising it's never been seen in the field;but still a bug is a bug, so patch all active branches.Noted while investigating whether we need to call pg_regfree after afailure return from pg_regcomp. Other than this bug, it turns out wedon't, so adjust comments appropriately.
1 parent2686da9 commit54fd196

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

‎src/backend/regex/regcomp.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ static struct fns functions = {
278278

279279
/*
280280
* pg_regcomp - compile regular expression
281+
*
282+
* Note: on failure, no resources remain allocated, so pg_regfree()
283+
* need not be applied to re.
281284
*/
282285
int
283286
pg_regcomp(regex_t*re,
@@ -1870,15 +1873,18 @@ rfree(regex_t *re)
18701873
g= (structguts*)re->re_guts;
18711874
re->re_guts=NULL;
18721875
re->re_fns=NULL;
1873-
g->magic=0;
1874-
freecm(&g->cmap);
1875-
if (g->tree!=NULL)
1876-
freesubre((structvars*)NULL,g->tree);
1877-
if (g->lacons!=NULL)
1878-
freelacons(g->lacons,g->nlacons);
1879-
if (!NULLCNFA(g->search))
1880-
freecnfa(&g->search);
1881-
FREE(g);
1876+
if (g!=NULL)
1877+
{
1878+
g->magic=0;
1879+
freecm(&g->cmap);
1880+
if (g->tree!=NULL)
1881+
freesubre((structvars*)NULL,g->tree);
1882+
if (g->lacons!=NULL)
1883+
freelacons(g->lacons,g->nlacons);
1884+
if (!NULLCNFA(g->search))
1885+
freecnfa(&g->search);
1886+
FREE(g);
1887+
}
18821888
}
18831889

18841890
#ifdefREG_DEBUG

‎src/backend/utils/adt/regexp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ RE_compile_and_cache(text *text_re, int cflags, Oid collation)
187187

188188
if (regcomp_result!=REG_OKAY)
189189
{
190-
/* re didn't compile */
190+
/* re didn't compile(no need for pg_regfree, if so)*/
191191
pg_regerror(regcomp_result,&re_temp.cre_re,errMsg,sizeof(errMsg));
192-
/* XXX should we pg_regfree here? */
193192
ereport(ERROR,
194193
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
195194
errmsg("invalid regular expression: %s",errMsg)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp