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: