Browse Source

Fix parsing start-line for avoiding response header injection

xtne6f 9 năm trước cách đây
mục cha
commit
81a72a9c59
1 tập tin đã thay đổi với 5 bổ sung3 xóa
  1. 5 3
      src/civetweb.c

+ 5 - 3
src/civetweb.c

@@ -7017,6 +7017,7 @@ static int
 parse_http_message(char *buf, int len, struct mg_request_info *ri)
 parse_http_message(char *buf, int len, struct mg_request_info *ri)
 {
 {
 	int is_request, request_length;
 	int is_request, request_length;
+	char *start_line;
 
 
 	if (!ri) {
 	if (!ri) {
 		return 0;
 		return 0;
@@ -7037,9 +7038,10 @@ parse_http_message(char *buf, int len, struct mg_request_info *ri)
 		while (*buf != '\0' && isspace(*(unsigned char *)buf)) {
 		while (*buf != '\0' && isspace(*(unsigned char *)buf)) {
 			buf++;
 			buf++;
 		}
 		}
-		ri->request_method = skip(&buf, " ");
-		ri->request_uri = skip(&buf, " ");
-		ri->http_version = skip(&buf, "\r\n");
+		start_line = skip(&buf, "\r\n");
+		ri->request_method = skip(&start_line, " ");
+		ri->request_uri = skip(&start_line, " ");
+		ri->http_version = start_line;
 
 
 		/* HTTP message could be either HTTP request or HTTP response, e.g.
 		/* HTTP message could be either HTTP request or HTTP response, e.g.
 		 * "GET / HTTP/1.0 ...." or  "HTTP/1.0 200 OK ..." */
 		 * "GET / HTTP/1.0 ...." or  "HTTP/1.0 200 OK ..." */