10000 Fix bug in to_tsquery(). · jcsston/postgres@26d73dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 26d73dd

Browse files
committed
Fix bug in to_tsquery().
We were using memcpy() to copy to a possibly overlapping memory region, which is a no-no. Use memmove() instead.
1 parent 82992a4 commit 26d73dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/tsearch/to_tsany.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
342342
if (query->size == 0)
343343
PG_RETURN_TSQUERY(query);
344344

345+
/* clean out any stopword placeholders from the tree */
345346
res = clean_fakeval(GETQUERY(query), &len);
346347
if (!res)
347348
{
@@ -351,6 +352,10 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
351352
}
352353
memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(QueryItem));
353354

355+
/*
356+
* Removing the stopword placeholders might've resulted in fewer
357+
* QueryItems. If so, move the operands up accordingly.
358+
*/
354359
if (len != query->size)
355360
{
356361
char *oldoperand = GETOPERAND(query);
@@ -359,7 +364,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
359364
Assert(len < query->size);
360365

361366
query->size = len;
362-
memcpy((void *) GETOPERAND(query), oldoperand, VARSIZE(query) - (oldoperand - (char *) query));
367+
memmove((void *) GETOPERAND(query), oldoperand, VARSIZE(query) - (oldoperand - (char *) query));
363368
SET_VARSIZE(query, COMPUTESIZE(len, lenoperand));
364369
}
365370

0 commit comments

Comments
 (0)
0