[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [tor-bugs] #18907 [Core Tor/Tor]: tor_gettimeofday_cached_monotonic, as designed, could stall indefinitely
#18907: tor_gettimeofday_cached_monotonic, as designed, could stall indefinitely
--------------------------+---------------------
Reporter: nickm | Owner:
Type: defect | Status: new
Priority: Medium | Milestone:
Component: Core Tor/Tor | Version:
Severity: Normal | Resolution:
Keywords: 029-proposed | Actual Points:
Parent ID: | Points:
Reviewer: | Sponsor:
--------------------------+---------------------
Comment (by nickm):
I think the code for a 'fixed' version would look something like this.
(Untested, probably has a sign bug or something.)
{{{
void
tor_gettimeofday_cached_monotonic(struct timeval *tv)
{
static struct timeval last_tv = { 0, 0 };
static struct timeval offset = { 0, 0 };
tor_gettimeofday_cached(tv);
timeradd(tv, &offset, tv);
if (timercmp(tv, &last_tv, OP_LT)) {
/* Time jumped backwards. Instead, we're going to increment 'offset'
by
enough so that no time passed at all. */
timersub(&last_tv, tv, &offset);
memcpy(tv, &last_tv, sizeof(struct timeval));
} else {
memcpy(&last_tv, tv, sizeof(struct timeval));
}
}
}}}
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/18907#comment:1>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs