[PATCH] dropbear-051: errno bug fix

Jamie Lokier jamie at shareable.org
Tue Sep 23 01:23:39 WST 2008


Matt Johnston wrote:
> > is that errno is already set to non-zero
> > before strol is called, then strol is successful but since strol doesn't
> > reset errno to zero, the next line thinks that strol failed.
> 
> I've applied this now in a more general form with a new
> function m_str_to_int(). Funnily enough setting errno=EINVAL isn't
> actually defined by C99 - though most (all?) platforms seem
> to do that.

Single Unix Specification (aka. POSIX) does though.

http://www.opengroup.org/onlinepubs/000095399/functions/strtol.html

    The strtol() function shall not change the setting of errno if
    successful.

    Since 0, LONG_MIN or LLONG_MIN, and LONG_MAX or LLONG_MAX are
    returned on error and are also valid returns on success, an
    application wishing to check for error situations should set errno
    to 0, then call strtol() or strtoll(), then check errno.

RETURN VALUE

    Upon successful completion, these functions shall return the
    converted value, if any. If no conversion could be performed, 0
    shall be returned and errno may be set to EINVAL.

    If the correct value is outside the range of representable values,
    LONG_MIN, LONG_MAX, LLONG_MIN, or LLONG_MAX shall be returned
    (according to the sign of the value), and errno set to ERANGE.

-- Jamie



More information about the Dropbear mailing list