Clear errno in spell.c
Hello!
Several times in spell.c, we call strtol and then check the errno, but we
do not clear out errno = 0 before strtol, as is customary (and done
everywhere else in the codebase that I could find.) This could
hypothetically lead to us incorrectly logging an error.
Regards,
Jacob
Attachments:
v1-errno.patchapplication/octet-stream; name=v1-errno.patchDownload
diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c
index 018b66d2c69..146801885d7 100644
--- a/src/backend/tsearch/spell.c
+++ b/src/backend/tsearch/spell.c
@@ -375,6 +375,7 @@ getNextFlagFromString(IspellDict *Conf, const 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,
@@ -1037,6 +1038,7 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry,
char *next;
int i;
+ errno = 0;
i = strtol(s, &next, 10);
if (s == next || errno == ERANGE)
ereport(ERROR,
@@ -1164,6 +1166,7 @@ getAffixFlagSet(IspellDict *Conf, char *s)
int curaffix;
char *end;
+ errno = 0;
curaffix = strtol(s, &end, 10);
if (s == end || errno == ERANGE)
ereport(ERROR,
@@ -1740,6 +1743,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,
Jacob Brazeal <jacob.brazeal@gmail.com> writes:
Several times in spell.c, we call strtol and then check the errno, but we
do not clear out errno = 0 before strtol, as is customary (and done
everywhere else in the codebase that I could find.) This could
hypothetically lead to us incorrectly logging an error.
Yeah. Looking around, we seem quite haphazard about whether we
check errno at all after strtol and siblings. But certainly, doing
so without clearing it beforehand is a Bad Idea.
It's surprising that we've not heard reports of problems here. Maybe
the I/O involved in reading the dictionary file we're parsing clears
errno and then never sets it to ERANGE? But I didn't see an obvious
place where it cleared errno. Anyway, even if this isn't a live bug
it's surely a latent one, so I'll push your patch.
regards, tom lane