[PATCH] dropbear-051: errno bug fix

Farrell Aultman fja0568 at gmail.com
Mon Sep 22 02:48:34 WST 2008


Thanks Jamie, I agree with everything you said.  The code would be better
modified as you indicate.

On Sat, Sep 20, 2008 at 11:58 AM, Jamie Lokier <jamie at shareable.org> wrote:

> Farrell Aultman wrote:
> > The code assumed that when strol is successful, that it will set
> > errno to zero.  This is not the case, at least under uClinux.
>
> It's not the case in general, POSIX doesn't require it to be set to zero.
>
> > The man page does not indicate this either.  What can happen 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.
>
> That's right.  The correct way to call strtol in general, if you're
> checking errno after, is to set errno to zero before.
>
> Since reading errno can be slow (in threaded programs), you might want
> to check if the result from strtol is LONG_MIN or LONG_MAX before
> checking errno.
>
> -- Jamie
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ucc.gu.uwa.edu.au/pipermail/dropbear/attachments/20080921/a92855de/attachment.htm 


More information about the Dropbear mailing list