From 5f569df69b0795e535afe3c85556bf7b3c431b0e Mon Sep 17 00:00:00 2001 From: Sagar Narayan <113566055+sagaragas@users.noreply.github.com> Date: Fri, 4 Dec 2026 10:54:40 -0800 Subject: [PATCH] options: reject integer overflow in --stop-at parse_time() accumulated each numeric field into a signed int without an overflow check. Large values like --stop-at=20270101000000 or --stop-at=2147483648-01-01T00:00 wrapped negative, tripping the < 0 omitted-field checks and scheduling a stop at the next default date instead of failing. Values like 4294969333-01-01T00:00 or 2037-01-01T4294967296:00 wrapped into valid future years or hours, and values near INT_MAX overflowed int before subtracting '0'. Compute each digit before accumulating, reject values above INT_MAX in parse_time(), and add regression cases to testsuite/tests/transfer/stop-time.py. --- options.c | 5 ++++- testsuite/tests/transfer/stop-time.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/options.c b/options.c index 6bcee00dc..05bcb658f 100644 --- a/options.c +++ b/options.c @@ -1388,7 +1388,10 @@ static time_t parse_time(const char *arg) return (time_t)-1; n = 0; do { - n = n * 10 + *cp++ - '0'; + int digit = *cp++ - '0'; + if (n > (INT_MAX - digit) / 10) + return (time_t)-1; + n = n * 10 + digit; } while (isDigit(cp)); if (*cp == ':') in_date = 0; diff --git a/testsuite/tests/transfer/stop-time.py b/testsuite/tests/transfer/stop-time.py index 070aee579..da3260866 100644 --- a/testsuite/tests/transfer/stop-time.py +++ b/testsuite/tests/transfer/stop-time.py @@ -27,6 +27,19 @@ if proc.returncode == 0: test_fail("--stop-at with a past time was not rejected") +for opt in ( + '--stop-at=20270101000000', + '--stop-at=2147483648-01-01T00:00', + '--stop-at=4294969333-01-01T00:00', + '--stop-at=2037-01-01T4294967296:00', +): + rmtree(TODIR) + proc = run_rsync('-a', opt, f'{src}/', f'{TODIR}/', + check=False, capture_output=True) + if proc.returncode == 0 or 'invalid --stop-at format' not in proc.stderr: + test_fail(f"{opt} was not rejected cleanly " + f"(rc={proc.returncode}, stderr={proc.stderr!r})") + rmtree(TODIR) run_rsync('-a', '--stop-after=60', f'{src}/', f'{TODIR}/') for rel in rels: