소스 검색

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 9 년 전
부모
커밋
3b6461d2a0
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  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) {
 		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')