[PATCH] [tldap] check for successful string conversion

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Jan 10 10:47:00 UTC 2019


On Thu, Jan 10, 2019 at 11:35:18AM +0100, swen via samba-technical wrote:
> > > Upon successful completion, these functions shall return the
> > > converted
> > > value, if any. If no conversion could be performed, 0 shall be
> > > returned [Option Start]  and errno may be set to [EINVAL]. [Option
> > > End] If the correct value is outside the range of representable
> > > values, {ULONG_MAX} or {ULLONG_MAX} shall be returned and errno set
> > > to
> > > [ERANGE].
> > 
> > Assuming that all implementations actually do the [Option] piece, we
> > need to check for result 0 or ULLONG_MAX *together* with errno. Just
> > checking for errno is not sufficient.
> It is sufficient because errno is set to zero before strtoull() is
> triggered.

How do you read the "and" conjunction in the documentation? I would
rather check for the precise documented conditions. According to the
documentation, a successful conversion of the string "1" could return
the number 1 and yet set errno to something !=0. Probably a weird
implementation, but legal according to the spec.

> In fact, this reference is wrong.
> You cannot assume, that if the return value is zero and errno == EINVAL
> that your conversion failed. The errno might have been be set to EINVAL
> from an earlier command and strtoull just "correctly" returned zero.
> This way you end up with a false positive.

You're right. Feel free to fix this.

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: 0551-370000-0, mailto:kontakt at sernet.de
Gesch.F.: Dr. Johannes Loxen und Reinhild Jung
AG Göttingen: HR-B 2816 - http://www.sernet.de



More information about the samba-technical mailing list