2020-11-11 Paul Eggert <eggert@cs.ucla.edu>
+ time_rz: simplify CVE-2017-7476 fix
+ * lib/time_rz.c: Do not include limits.h; I think it was included
+ under the mistaken impression that limits.h defines SIZE_MAX.
+ (SIZE_MAX): Remove.
+ (save_abbr): Put string length into a ptrdiff_t variable,
+ so that the size comparison works naturally. This
+ fixes CVE-2017-7476 in a cleaner way.
+
parse-datetime: streamline overflow checking
When parse-datetime.y’s overflow code was written, INT_ADD_WRAPV
did not work for unsigned destinations, and since time_t might
#include <time.h>
#include <errno.h>
-#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include "flexmember.h"
#include "time-internal.h"
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
/* The approximate size to use for small allocation requests. This is
the largest "small" request for the GNU C library malloc. */
enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
{
if (! (*zone_copy || (zone_copy == tz->abbrs && tz->tz_is_set)))
{
- size_t zone_size = strlen (zone) + 1;
- size_t zone_used = zone_copy - tz->abbrs;
- if (SIZE_MAX - zone_used < zone_size)
- {
- errno = ENOMEM;
- return false;
- }
- if (zone_used + zone_size < ABBR_SIZE_MIN)
+ ptrdiff_t zone_size = strlen (zone) + 1;
+ if (zone_size < tz->abbrs + ABBR_SIZE_MIN - zone_copy)
extend_abbrs (zone_copy, zone, zone_size);
else
{