From 3b6461d2a02cc0c9940d9502f56da3541037f5ba Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 18 Sep 2016 21:59:09 +0200 Subject: [PATCH] exception if invalid throttle parameter is used If '*' is used as `throttle` parameter, there is a segfault at the first request (see #350). This is a quick fix to avoid the segfault exception. Note that in general civetweb.c does not check parameters in advance, in order to keep the code simple. Other invalid parameters may still cause exceptions. It is the responsibility of the caller to pass valid parameters to mg_start. --- src/civetweb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/civetweb.c b/src/civetweb.c index 379b5a32..98ada7a9 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -9680,9 +9680,9 @@ set_throttle(const char *spec, uint32_t remote_ip, const char *uri) while ((spec = next_option(spec, &vec, &val)) != NULL) { mult = ','; - if (sscanf(val.ptr, "%lf%c", &v, &mult) < 1 || v < 0 - || (lowercase(&mult) != 'k' && lowercase(&mult) != 'm' - && mult != ',')) { + if ((val.ptr == NULL) || (sscanf(val.ptr, "%lf%c", &v, &mult) < 1) + || (v < 0) || ((lowercase(&mult) != 'k') + && (lowercase(&mult) != 'm') && (mult != ','))) { continue; } v *= (lowercase(&mult) == 'k')