Re: Converting tab-complete.c's else-if chain to a switch
Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Thomas Munro <thomas.munro@gmail.com>, Andres Freund <andres@anarazel.de>, pgsql-hackers@lists.postgresql.org
Date: 2024-10-10T07:22:12Z
Lists: pgsql-hackers
Attachments
- v1-0001-Fix-psql-segfault-on-word-completion-without-matc.patch (application/octet-stream) patch v1-0001
Hi,
bd1276a3c9 seems to have introduced a segfault when trying to complete
a word that doesn't have any match. For example, 'postgres=# z\t' will
yield the following backtrace:
#0: psql`pg_strcasecmp(s1="", s2="ACCESS METHOD") at pgstrcasecmp.c:40:39
#1: psql`psql_completion(text=":pgss-", start=0, end=6) at
tab-complete.in.c:2033:8
The matching code in tab-complete.in.c:
if (matches == NULL)
{
const pgsql_thing_t *wac;
for (wac = words_after_create; wac->name != NULL; wac++)
{
if (pg_strcasecmp(prev_wd, wac->name) == 0)
{
psql tries to read the previous word when matches are NULL. However,
there's no previous word set here, leading to the segfault.
I've attached a patch that checks if the previous word does exist
before trying to use it, along with an additional test for this
codepath.
Commits
-
Don't hard-code the input file name in gen_tabcomplete.pl's output.
- c75c6f8d280a 18.0 landed
-
Avoid possible segfault in psql's tab completion.
- 95eb4cd4ff06 18.0 landed
-
Convert tab-complete's long else-if chain to a switch statement.
- f391d9dc93a2 18.0 landed
-
Prepare tab-complete.c for preprocessing.
- bd1276a3c943 18.0 landed
-
Invent "MatchAnyN" option for tab-complete.c's Matches/MatchesCS.
- ef0938f7bdd0 18.0 landed