Skip to content

Commit f1c1baf

Browse files
committed
Clear errno before calling strtol() in spell.c.
Per POSIX, a caller of strtol() that wishes to check for errors must set errno to 0 beforehand. Several places in spell.c neglected that, so that they risked delivering a false overflow error in case errno had been ERANGE already. Given the lack of field reports, this case may be unreachable at present --- but it's surely trouble waiting to happen, so fix it. Author: Jacob Brazeal <jacob.brazeal@gmail.com> Discussion: https://postgr.es/m/CA+COZaBhsq6EromFm+knMJfzK6nTpG23zJ+K2=nfUQQXcj_xcQ@mail.gmail.com Backpatch-through: 13
1 parent 308d0d4 commit f1c1baf

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/backend/tsearch/spell.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
374374
stop = (maxstep == 0);
375375
break;
376376
case FM_NUM:
377+
errno = 0;
377378
s = strtol(*sflagset, &next, 10);
378379
if (*sflagset == next || errno == ERANGE)
379380
ereport(ERROR,
@@ -1056,6 +1057,7 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry,
10561057
char *next;
10571058
int i;
10581059

1060+
errno = 0;
10591061
i = strtol(s, &next, 10);
10601062
if (s == next || errno == ERANGE)
10611063
ereport(ERROR,
@@ -1183,6 +1185,7 @@ getAffixFlagSet(IspellDict *Conf, char *s)
11831185
int curaffix;
11841186
char *end;
11851187

1188+
errno = 0;
11861189
curaffix = strtol(s, &end, 10);
11871190
if (s == end || errno == ERANGE)
11881191
ereport(ERROR,
@@ -1754,6 +1757,7 @@ NISortDictionary(IspellDict *Conf)
17541757

17551758
if (*Conf->Spell[i]->p.flag != '\0')
17561759
{
1760+
errno = 0;
17571761
curaffix = strtol(Conf->Spell[i]->p.flag, &end, 10);
17581762
if (Conf->Spell[i]->p.flag == end || errno == ERANGE)
17591763
ereport(ERROR,

0 commit comments

Comments
 (0)