]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Ensure Soundex difference() function handles empty input sanely.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 May 2023 14:53:42 +0000 (10:53 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 May 2023 14:53:42 +0000 (10:53 -0400)
commit0409c7fc746b2597edeaab3132d3f3554660283d
treeeff7b95d87409cabdf1f1202eb3e162cf856f438
parent71fe2372278760714a442c82eb2ef524b7ea392a
Ensure Soundex difference() function handles empty input sanely.

fuzzystrmatch's difference() function assumes that _soundex()
always initializes its output buffer fully.  This was not so for
the case of a string containing no alphabetic characters, resulting
in unstable output and Valgrind complaints.

Fix by using memset() to fill the whole buffer in the early-exit
case.  Also make some cosmetic improvements (I didn't care for the
random switches between "instr[0]" and "*instr" notation).

Report and diagnosis by Alexander Lakhin (bug #17935).
Back-patch to all supported branches.

Discussion: https://postgr.es/m/17935-b99316aa79c18513@postgresql.org
contrib/fuzzystrmatch/expected/fuzzystrmatch.out
contrib/fuzzystrmatch/fuzzystrmatch.c
contrib/fuzzystrmatch/sql/fuzzystrmatch.sql