postgresql/src/backend
Tom Lane bc428b12ac Fix ts_headline() edge cases for empty query and empty search text.
tsquery's GETQUERY() macro is only safe to apply to a tsquery
that is known non-empty; otherwise it gives a pointer to garbage.
Before commit 5a617d75d, ts_headline() avoided this pitfall, but
only in a very indirect, nonobvious way.  (hlCover could not reach
its TS_execute call, because if the query contains no lexemes
then hlFirstIndex would surely return -1.)  After that commit,
it fell into the trap, resulting in weird errors such as
"unrecognized operator" and/or valgrind complaints.  In HEAD,
fix this by not calling TS_execute_locations() at all for an
empty query.  In the back branches, add a defensive check to
hlCover() --- that's not fixing any live bug, but I judge the
code a bit too fragile as-is.

Also, both mark_hl_fragments() and mark_hl_words() were careless
about the possibility of empty search text: in the cases where
no match has been found, they'd end up telling mark_fragment() to
mark from word indexes 0 to 0 inclusive, even when there is no
word 0.  This is harmless since we over-allocated the prs->words
array, but it does annoy valgrind.  Fix so that the end index is -1
and thus mark_fragment() will do nothing in such cases.

Bottom line is that this fixes a live bug in HEAD, but in the
back branches it's only getting rid of a valgrind nitpick.
Back-patch anyway.

Per report from Alexander Lakhin.

Discussion: https://postgr.es/m/c27f642d-020b-01ff-ae61-086af287c4fd@gmail.com
2023-04-06 15:52:37 -04:00
..
access Fix dereference of dangling pointer in GiST index buffering build. 2023-03-29 11:31:30 -04:00
bootstrap Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
catalog Allow REPLICA IDENTITY to be set on an index that's not (yet) valid. 2023-01-21 13:10:30 -05:00
commands Ensure acquire_inherited_sample_rows sets its output parameters. 2023-03-31 10:08:40 -04:00
executor Fix oversights in array manipulation. 2023-03-26 13:41:06 -04:00
foreign Remove bogus "extern" annotations on function definitions. 2018-02-19 12:07:44 -05:00
jit Fix typos in comments, code and documentation 2023-01-03 16:26:38 +09:00
lib Fix lock assertions in dshash.c. 2022-07-11 15:54:24 +12:00
libpq Fix handling of SCRAM-SHA-256's channel binding with RSA-PSS certificates 2023-02-15 10:12:40 +09:00
main Fix outdated --help message for postgres -f 2022-08-15 13:37:44 +09:00
nodes Further fixes for MULTIEXPR_SUBLINK fix. 2022-09-06 16:38:18 -04:00
optimizer Fix MULTIEXPR_SUBLINK with partitioned target tables, yet again. 2023-02-25 14:44:14 -05:00
parser Fix List memory issue in transformColumnDefinition 2023-03-31 12:15:39 +13:00
partitioning Avoid using ambiguous word "non-negative" in error messages. 2021-07-28 01:24:51 +09:00
po Translation updates 2023-02-06 12:22:35 +01:00
port Make EXEC_BACKEND more convenient on macOS. 2021-08-13 11:10:49 +12:00
postmaster Small tidyup for commit d41a178b, part II. 2023-03-17 14:48:08 +13:00
regex Defend against stack overrun in a few more places. 2022-08-24 13:01:40 -04:00
replication Don't repeatedly register cache callbacks in pgoutput plugin. 2023-02-23 15:40:28 -05:00
rewrite Fix more bugs caused by adding columns to the end of a view. 2023-03-07 18:21:37 -05:00
snowball In the Snowball dictionary, don't try to stem excessively-long words. 2022-08-31 10:42:05 -04:00
statistics Build inherited extended stats on partitioned tables 2022-01-15 18:32:20 +01:00
storage Fix race in SERIALIZABLE READ ONLY. 2023-03-09 17:26:06 +13:00
tcop Rethink handling of [Prevent|Is]InTransactionBlock in pipeline mode. 2022-12-13 14:23:59 -05:00
tsearch Fix ts_headline() edge cases for empty query and empty search text. 2023-04-06 15:52:37 -04:00
utils Fix oversights in array manipulation. 2023-03-26 13:41:06 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Rearrange makefile rules for running Gen_fmgrtab.pl. 2018-05-03 17:54:18 -04:00
nls.mk Translation updates 2018-09-17 08:40:36 +02:00