buglwIP - A Lightweight TCP/IP stack - Bugs: bug #29769, sys_check_timeouts: sys_now() may...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #29769: sys_check_timeouts: sys_now() may overflow

Submitter:  Simon Goldschmidt <goldsimon>
Submitted:  Tue 04 May 2010 10:26:23 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  CVS Head

Tue 04 May 2010 07:29:01 PM UTC, comment #2: 

That should work on any architecture since sys_now() and 'last_time' both give u32_t values.

Fixed by adding this macro as 'LWIP_U32_DIFF' to def.h.

Thanks for the code ;-)

Simon Goldschmidt <goldsimon>
Group administrator
Tue 04 May 2010 01:39:19 PM UTC, comment #1: 

I use the following macro:

#define TIMEDIFF(a,b) (((a) >= (b)) ? ((a)-(b)) : (((a)+((b)^0xFFFFFFFF)+1)))

It's used like that:

time_diff = TIMEDIFF(sys_now(), last_time);

Seems to be the same as the proposed one and I can confirm it works (at least on a 32-bit micro).

Iordan Neshev <iordan_neshev>
Tue 04 May 2010 10:26:23 AM UTC, original submission:  

For NO_SYS==1, sys_check_timeouts uses sys_now() time-difference to check for timeouts. Now when the time wraps around (after 49-something days), no more timers will get called. Possible solution:

> void
> sys_check_timeouts(void)
> {
>    struct sys_timeo *tmptimeout;
>    u32_t diff;
>    sys_timeout_handler h;
>    void *arg;
>    int had_one;
>    u32_t now;
> #if LWIP_DEBUG_TIMERNAMES
>    const char *handler_name;
> #endif /* LWIP_DEBUG_TIMERNAMES */
>
>    now = sys_now();
>    if (next_timeout) {
>      /* @todo: wrap around? */
> // --------- new code
>      if (now < timeouts_last_time)
>        diff = ( 0xFFFFFFFF - timeouts_last_time ) + now + 1 ;
>      else
> // --------- end of new code
>      diff = now - timeouts_last_time;
>

Simon Goldschmidt <goldsimon>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by iordan_neshev (Posted a comment)
  • -email is unavailable- added by goldsimon (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-05-04 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code