OpenNTPD daemon with OpenSSL implementation & flexible configurability
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
893 B

  1. From: Pekka Helenius <fincer89@hotmail.com>
  2. Date: Thu, 13 Aug 2020 21:55:20 +0300
  3. Subject: Cast constraint median time value to unsigned long. Fixes overflow on 32-bit systems.
  4. --- a/src/constraint.c 2020-08-03 23:43:48.584926017 +0300
  5. +++ b/src/constraint.c 2020-08-13 21:54:44.579053808 +0300
  6. @@ -941,7 +941,14 @@ constraint_update(void)
  7. /* calculate median */
  8. i = cnt / 2;
  9. if (cnt % 2 == 0)
  10. - conf->constraint_median = (values[i - 1] + values[i]) / 2;
  11. +
  12. + /*
  13. + * Casting to unsigned long (ul) is required on 32-bit systems.
  14. + * Otherwise, the summed value exceed the maximum 32-bit time_t value and overflows
  15. + * before divide operation, resulting to a great negative value which again leads to
  16. + * an invalid constraint_median value.
  17. + */
  18. + conf->constraint_median = ( (unsigned long)(values[i - 1] + values[i]) ) / 2;
  19. else
  20. conf->constraint_median = values[i];