Avoid possible segfault in psql's tab completion.
authorTom Lane <[email protected]>
Thu, 10 Oct 2024 20:17:38 +0000 (16:17 -0400)
committerTom Lane <[email protected]>
Thu, 10 Oct 2024 20:17:38 +0000 (16:17 -0400)
commit95eb4cd4ff0648afc32abbfaacc9718f6b91bf7b
tree77a05e6f59ba3669d618ee4a8eb43f1a451c1fa8
parentfd64ed60b62697984bb69a09a3ae19fbe2905eb6
Avoid possible segfault in psql's tab completion.

Fix oversight in bd1276a3c: the "words_after_create" stanza in
psql_completion() requires previous_words_count > 0, since it uses
prev_wd.  This condition was formerly assured by the if-else chain
above it, but no more.  If there were no previous words then we'd
dereference an uninitialized pointer, possibly causing a segfault.

Report and patch by Anthonin Bonnefoy.

Discussion: https://postgr.es/m/CAO6_XqrSRE7c_i+D7Hm07K3+6S0jTAmMr60RY41XzaA29Ae5uA@mail.gmail.com
src/bin/psql/tab-complete.in.c