Ver código fonte

Fix for (null) in "Bad request" response

If a client sends a request that isn't handled (like 'PROPPATCH /example.c HTTP/1.1') then 'is_valid_http_method()' is called before the HTTP version is parsed which means the response sent to the client is malformed ('HTTP/(null) 400 Bad Request'), so call 'is_valid_http_method()' after parsing the HTTP version.
drew-wells 3 anos atrás
pai
commit
5c2d042179
1 arquivos alterados com 5 adições e 5 exclusões
  1. 5 5
      src/civetweb.c

+ 5 - 5
src/civetweb.c

@@ -10637,11 +10637,6 @@ parse_http_request(char *buf, int len, struct mg_request_info *ri)
 		return -1;
 		return -1;
 	}
 	}
 
 
-	/* Check for a valid http method */
-	if (!is_valid_http_method(ri->request_method)) {
-		return -1;
-	}
-
 	/* The second word is the URI */
 	/* The second word is the URI */
 	ri->request_uri = buf;
 	ri->request_uri = buf;
 
 
@@ -10662,6 +10657,11 @@ parse_http_request(char *buf, int len, struct mg_request_info *ri)
 		return -1;
 		return -1;
 	}
 	}
 	ri->http_version += 5;
 	ri->http_version += 5;
+	
+	/* Check for a valid http method */
+	if (!is_valid_http_method(ri->request_method)) {
+		return -1;
+	}
 
 
 	/* Parse all HTTP headers */
 	/* Parse all HTTP headers */
 	ri->num_headers = parse_http_headers(&buf, ri->http_headers);
 	ri->num_headers = parse_http_headers(&buf, ri->http_headers);