safe_timer_diff is meant to avoid overflow (or perhaps negative return values) but doesn't. (It was introduced to tor 0.2.8.0-alpha-dev in #3199 (moved).)
For example:
safe_timer_diff(INT_MIN, INT_MAX) returns -1 on a system where TIME_T_IS_SIGNED. It should return a (clipped) value representing the largest integer difference possible, such as INT_MAX.
I'm sure there are equivalent issues where TIME_T_IS_UNSIGNED, but I can't think of any right now.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
I'd look at a patch for these if we got one, but AFAIK nobody's looking at them right now, and there's no reason to expect them to get done this month.
It would be great to implement and test this once, and then use it here, and when we parse integers from strings, and perhaps in other locations that (attempt) to detect integer overflow.
I can imagine us wanting the following behaviours:
saturate (clip to MIN/MAX) on over/underflow
fail on over/underflow
wrap on over/underflow (that is, a simple cast to a wide unsigned type)
The checked_add_1() function in http://blog.regehr.org/archives/1139 compiles efficiently on both clang and gcc, let's start with that as a base. (If we need to, we could implement it as a macro which expands into type-specific or outcome-specific functions.)
bug17682 in my public repository should fix this. It's not the beautiful thing that we might have had in mind, but it has the advantage of having been written.
+ /* There were no computers at signed TIME_MIN, and nothing that could run+ * Tor. It's a bug if 'now' is around then. */+ tor_assert(now > TIME_MIN + LONGEST_TIMER_PERIOD);
Doesn't shadow rely on starting Tor at the epoch?
(I think I heard that once, I'm not sure how accurate it is.)
+ if (next < now - LONGEST_TIMER_PERIOD)+ return LONGEST_TIMER_PERIOD;
Do you mean next > now - LONGEST_TIMER_PERIOD?
Given the assertion, now - LONGEST_TIMER_PERIOD never underflows, so now - LONGEST_TIMER_PERIOD > TIME_MIN.
And if next > now, then it's never true that next < now - LONGEST_TIMER_PERIOD.
/* There were no computers at signed TIME_MIN, and nothing that could run
* Tor. It's a bug if 'now' is around then. */
tor_assert(now > TIME_MIN + LONGEST_TIMER_PERIOD);
}}}
Doesn't shadow rely on starting Tor at the epoch?
(I think I heard that once, I'm not sure how accurate it is.)
I believe it once did. But in any case, TIME_MIN on a 32-bit computer isn't 1970 -- it's 1902. And on a 64-bit time_t, it is 292 billion years in the past, whereas current cosmological models only put our universe at 13.8 billion years old.
(I continue to maintained that unsigned time_t doesn't actually exist. Adding a ticket to remove unsigned TIME_T support as #18184 (moved) )
{{{
if (next < now - LONGEST_TIMER_PERIOD)
return LONGEST_TIMER_PERIOD;
}}}
Do you mean next > now - LONGEST_TIMER_PERIOD?
Given the assertion, now - LONGEST_TIMER_PERIOD never underflows, so now - LONGEST_TIMER_PERIOD > TIME_MIN.
And if next > now, then it's never true that next < now - LONGEST_TIMER_PERIOD.
D'oh. Trying again. I think the fixup in bug17682 should be right.
Looks good, just sent an email to Rob to check out how my vague memories of shadow correspond to reality. But I don't think we need to wait for his reply, we can fix that in another ticket if needed, or he can patch it on his end.
Doesn't shadow rely on starting Tor at the epoch?
(I think I heard that once, I'm not sure how accurate it is.)
I believe it once did.
Shadow internally starts at time 0, and maintains a simulation clock that ticks with nanosecond granularity. Because applications like Tor rely on time() and gettimeofday() to properly function, the time that Shadow emulates to Tor indeed starts at the epoch. (I.e., at the first tick, Shadow would return 0 if Tor called time() or gettimeofday()).