From abe8521e06c337a5c291d95954b5e7b5708ecb95 Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 13 Mar 2004 18:03:39 +0000 Subject: [PATCH] Detect arithmetic overflow (poorly) in insert_time(), which diagnoses the failure to handle large arguments to -mtime. The existing code does careful computation and then bungs the value into a time_t, which ruins all our careful effort. The new code is not a great improvement. We just check the result to detect overflow, rather than actually avoiding the overflow. --- find/parser.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/find/parser.c b/find/parser.c index 1aebe7b..be58a3a 100644 --- a/find/parser.c +++ b/find/parser.c @@ -1579,8 +1579,22 @@ insert_time (char **argv, int *arg_ptr, PFB pred) return (false); if (!get_num_days (argv[*arg_ptr], &num_days, &c_type)) return (false); - t = (cur_day_start - num_days * DAYSECS - + ((c_type == COMP_GT) ? DAYSECS - 1 : 0)); + + /* Figure out the timestamp value we are looking for. */ + t = ( cur_day_start - num_days * DAYSECS + + ((c_type == COMP_GT) ? DAYSECS - 1 : 0)); +#if 1 + intmax_t val = ( (intmax_t)cur_day_start - num_days * DAYSECS + + ((c_type == COMP_GT) ? DAYSECS - 1 : 0)); + t = val; + + /* Check for possibility of an overflow */ + if ( (intmax_t)t != val ) + { + error (1, 0, "arithmetic overflow while converting %s days to a number of seconds", argv[*arg_ptr]); + } +#endif + our_pred = insert_primary (pred); our_pred->args.info.kind = c_type; our_pred->args.info.negative = t < 0; -- 2.11.4.GIT