Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow in computation of constraint_median with 32-bit time_t #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaellass
Copy link

On system where time_t is a signed 32-bit integer (e.g., glibc on 32-bit x86), currently the computation of conf->constraint_median causes an integer overflow. Subsequently, all time sources are considered invalid due to a high deviation from the constraint.

This PR adds a patch that uses long long for the computation, which fixes this issue with 32-bit x86 glibc and should not harm other systems. If the cast should be avoided, an alternative with slightly larger rounding error would be something like

conf->constraint_median = (values[i - 1] / 2 + values[i] / 2);

Adding two time_t values representing the current time overflows if the
underlying type is a 32 bit integer. Use long long for the addition
which should always consist of at least 64 bit.

This fixes constraints erroneously considered invalid due to an
incorrectly computed median.
@leahneukirchen
Copy link

You can use the trick (a / 2) + (b / 2) + (a & b & 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants