Skip to content

Commit b527394

Browse files
committed
Ensure maxlen is at leat 1 in dict_int
The dict_int text search dictionary template accepts maxlen parameter, which is then used to cap the length of input strings. The value was not properly checked, and the code simply does txt[d->maxlen] = '\0'; to insert a terminator, leading to segfaults with negative values. This commit simply rejects values less than 1. The issue was there since dct_int was introduced in 9.3, so backpatch all the way back to 9.4 which is the oldest supported version. Reported-by: cili Discussion: https://postgr.es/m/16144-a36a5bef7657047d@postgresql.org Backpatch-through: 9.4
1 parent bf39b3a commit b527394

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

contrib/dict_int/dict_int.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ dintdict_init(PG_FUNCTION_ARGS)
4545
if (strcmp(defel->defname, "maxlen") == 0)
4646
{
4747
d->maxlen = atoi(defGetString(defel));
48+
49+
if (d->maxlen < 1)
50+
ereport(ERROR,
51+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
52+
errmsg("maxlen value has to be >= 1")));
4853
}
4954
else if (strcmp(defel->defname, "rejectlong") == 0)
5055
{

contrib/dict_int/expected/dict_int.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,5 @@ select ts_lexize('intdict', '314532610153');
300300
{314532}
301301
(1 row)
302302

303+
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);
304+
ERROR: maxlen value has to be >= 1

contrib/dict_int/sql/dict_int.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ select ts_lexize('intdict', '252281774');
5151
select ts_lexize('intdict', '313425');
5252
select ts_lexize('intdict', '641439323669');
5353
select ts_lexize('intdict', '314532610153');
54+
55+
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);

0 commit comments

Comments
 (0)