pgsql: Fix not-terribly-safe coding in NIImportOOAffixes() and NIImport

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix not-terribly-safe coding in NIImportOOAffixes() and NIImport
Date: 2016-03-07 00:21:26
Message-ID: E1acivO-0005en-JJ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix not-terribly-safe coding in NIImportOOAffixes() and NIImportAffixes().

There were two places in spell.c that supposed that they could search
for a location in a string produced by lowerstr() and then transpose
the offset into the original string. But this fails completely if
lowerstr() transforms any characters into characters of different byte
length, as can happen in Turkish UTF8 for instance.

We'd added some comments about this coding in commit 51e78ab4ff328296,
but failed to realize that it was not merely confusing but wrong.

Coverity complained about this code years ago, but in such an opaque
fashion that nobody understood what it was on about. I'm not entirely
sure that this issue *is* what it's on about, actually, but perhaps
this patch will shut it up -- and in any case the problem is clear.

Back-patch to all supported branches.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/b3e05097e58051a7816ed734074fd76345687e0c

Modified Files
--------------
src/backend/tsearch/spell.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2016-03-07 00:30:08 pgsql: Fix wrong allocation size in c8f621c43.
Previous Message Tom Lane 2016-03-06 23:24:00 pgsql: Fix unportable usage of <ctype.h> functions.