tool_getparam: limit --rate to be smaller than number of ms

Currently, curl allows users to specify absurd request rates that might
be higher than the number of milliseconds in the unit (ex: curl --rate
3600050/h http://localhost:8080 does not error out despite there being
only 3600000ms in a hour).

This change adds a conditional check before the millisecond calculation
making sure that the number is not higher than the numerator (the unit)
If the number is higher, curl errors out with PARAM_NUMBER_TOO_LARGE

Closes #12116
This commit is contained in:
Sohom Datta 2023-10-13 23:01:16 +02:00 committed by Daniel Stenberg
parent e2006b5d58
commit 8993efc2a5
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -1043,6 +1043,12 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
break;
}
}
if(denominator > numerator) {
err = PARAM_NUMBER_TOO_LARGE;
break;
}
global->ms_per_transfer = numerator/denominator;
}
break;