Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7fb8801

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 67fc4c9 commit 7fb8801

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
@@ -375,6 +375,7 @@ getNextFlagFromString(IspellDict *Conf, const char **sflagset, char *sflag)
375375
stop = (maxstep == 0);
376376
break;
377377
case FM_NUM:
378+
errno = 0;
378379
s = strtol(*sflagset, &next, 10);
379380
if (*sflagset == next || errno == ERANGE)
380381
ereport(ERROR,
@@ -1037,6 +1038,7 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry,
10371038
char *next;
10381039
int i;
10391040

1041+
errno = 0;
10401042
i = strtol(s, &next, 10);
10411043
if (s == next || errno == ERANGE)
10421044
ereport(ERROR,
@@ -1164,6 +1166,7 @@ getAffixFlagSet(IspellDict *Conf, char *s)
11641166
int curaffix;
11651167
char *end;
11661168

1169+
errno = 0;
11671170
curaffix = strtol(s, &end, 10);
11681171
if (s == end || errno == ERANGE)
11691172
ereport(ERROR,
@@ -1740,6 +1743,7 @@ NISortDictionary(IspellDict *Conf)
17401743

17411744
if (*Conf->Spell[i]->p.flag != '\0')
17421745
{
1746+
errno = 0;
17431747
curaffix = strtol(Conf->Spell[i]->p.flag, &end, 10);
17441748
if (Conf->Spell[i]->p.flag == end || errno == ERANGE)
17451749
ereport(ERROR,

0 commit comments

Comments
 (0)