[BusyBox] Serious bug in udhcpc

Russ Dill Russ.Dill at asu.edu
Tue Apr 22 04:18:13 UTC 2003


On Mon, 2003-04-21 at 13:27, Bastian Blank wrote:
> On Mon, Apr 21, 2003 at 11:46:46AM -0700, Russ Dill wrote:
> > the value that it returns is seconds *since* epoch, and since it returns
> > a signed long, dates larger than 0x7FFFFFFF (sometime in 2038) don't
> > make sense. Its a broken system, in no way should the time ever have
> > been set to that value.
> 
> it's normal behaviour for a linux kernel on systems without a hardware
> clock, it sets the time to some random value.

wait, so the kernel actually boots, looks at the uninitialized hardware,
thinks for a moment, sticks its arm into the /dev/urandom bag, pulls out
a winner, and sticks it into seconds since epoch? On all the embedded
systems I've seen without a battery backed RTC, the clock is set to
epoch on boot. That would be really broken behavior to never initialize
the RTC, or to initialize it to a random value.

> > Basically, I don't want to add complex code to account ofr seriously
> > broken systems. Maybe add a if (time(0) < 0) printf("fscked time\n"); if
> > you are concerned about it.
> 
> cast the value to unsigned as proposed for supporting dates after 2037.

which value? timeout? how would that help? select expects a signed
value. But, for those who want an example:

#include <stdio.h>
#include <time.h>
#include <sys/time.h>
 
static unsigned long ulong;
static long slong;
 
int main (void)
{
        struct timeval tv;
        time_t sane = time(0);
        time_t fscked = 0xDEADBEEF;
 
        tv.tv_sec = ulong - sane;
        printf("sane timer (w/ulong): %ld seconds remaining, %s\n",
                tv.tv_sec, tv.tv_sec > 0 ? "will wait" : "will drop
through select");
        tv.tv_sec = slong - sane;
        printf("sane timer (w/slong): %ld seconds remaining, %s\n",
                tv.tv_sec, tv.tv_sec > 0 ? "will wait" : "will drop
through select");
 
        tv.tv_sec = ulong - fscked;
        printf("fsked timer (w/ulong): %ld seconds remaining, %s\n",
                tv.tv_sec, tv.tv_sec > 0 ? "will wait" : "will drop
through select");
        tv.tv_sec = slong - fscked;
        printf("fsked timer (w/slong): %ld seconds remaining, %s\n",
                tv.tv_sec, tv.tv_sec > 0 ? "will wait" : "will drop
through select");
 
        return 0;
}

sane timer (w/ulong): -1050984790 seconds remaining, will drop through
select
sane timer (w/slong): -1050984790 seconds remaining, will drop through
select
fsked timer (w/ulong): 559038737 seconds remaining, will wait
fsked timer (w/slong): 559038737 seconds remaining, will wait

note the positive amount of time remaining, when we were really looking
to get a large negative value. Similarly, a negative value + an
additional 10 seconds will also be a negative value. add to this that a
value telling it to wait indefinatiely (0x7FFFFFFF) will give it a
negative value, and drop though.



More information about the busybox mailing list