]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Clear errno before calling strtol() in spell.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 8 Mar 2025 16:24:22 +0000 (11:24 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 8 Mar 2025 16:24:57 +0000 (11:24 -0500)
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

src/backend/tsearch/spell.c

index 961eb2709ca06147ccc662be530f0c1253d56672..2c555ebdccef75f29c9999eebbb64fb4d95871b2 100644 (file)
@@ -374,6 +374,7 @@ getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
                                stop = (maxstep == 0);
                                break;
                        case FM_NUM:
+                               errno = 0;
                                s = strtol(*sflagset, &next, 10);
                                if (*sflagset == next || errno == ERANGE)
                                        ereport(ERROR,
@@ -1056,6 +1057,7 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry,
                char       *next;
                int                     i;
 
+               errno = 0;
                i = strtol(s, &next, 10);
                if (s == next || errno == ERANGE)
                        ereport(ERROR,
@@ -1183,6 +1185,7 @@ getAffixFlagSet(IspellDict *Conf, char *s)
                int                     curaffix;
                char       *end;
 
+               errno = 0;
                curaffix = strtol(s, &end, 10);
                if (s == end || errno == ERANGE)
                        ereport(ERROR,
@@ -1754,6 +1757,7 @@ NISortDictionary(IspellDict *Conf)
 
                        if (*Conf->Spell[i]->p.flag != '\0')
                        {
+                               errno = 0;
                                curaffix = strtol(Conf->Spell[i]->p.flag, &end, 10);
                                if (Conf->Spell[i]->p.flag == end || errno == ERANGE)
                                        ereport(ERROR,