diff options
author | Daniel Stenberg <daniel@haxx.se> | 2019-07-29 22:10:13 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2019-07-30 08:17:01 +0200 |
commit | db0a0dfb0eb41d39273b0590b992df58f38b9a4d (patch) | |
tree | cd429784d6d1a110620bf14ca745e19e21b85b1e /src/tool_paramhlp.c | |
parent | d23e87d551d2d99201d7eb275029b6f0660f5136 (diff) |
curl: cap the maximum allowed values for retry time arguments
... to avoid integer overflows later when multiplying with 1000 to
convert seconds to milliseconds.
Added test 1269 to verify.
Reported-by: Jason Lee
Closes #4166
Diffstat (limited to 'src/tool_paramhlp.c')
-rw-r--r-- | src/tool_paramhlp.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 3a4286c67..c9dac4f0f 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -198,6 +198,28 @@ ParameterError str2unum(long *val, const char *str) } /* + * Parse the string and write the long in the given address if it is below the + * maximum allowed value. Return PARAM_OK on success, otherwise a parameter + * error enum. ONLY ACCEPTS POSITIVE NUMBERS! + * + * Since this function gets called with the 'nextarg' pointer from within the + * getparameter a lot, we must check it for NULL before accessing the str + * data. + */ + +ParameterError str2unummax(long *val, const char *str, long max) +{ + ParameterError result = str2unum(val, str); + if(result != PARAM_OK) + return result; + if(*val > max) + return PARAM_NUMBER_TOO_LARGE; + + return PARAM_OK; +} + + +/* * Parse the string and write the double in the given address. Return PARAM_OK * on success, otherwise a parameter specific error enum. * |