Browse Source

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.
bel 8 years ago
parent
commit
3b6461d2a0
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/civetweb.c

+ 3 - 3
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) {
 	while ((spec = next_option(spec, &vec, &val)) != NULL) {
 		mult = ',';
 		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;
 			continue;
 		}
 		}
 		v *= (lowercase(&mult) == 'k')
 		v *= (lowercase(&mult) == 'k')