annotate Resources/Patches/mongoose-3.8-patch.diff @ 3383:367d0b618d70

todo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 May 2019 17:31:44 +0200
parents 4a8e8a96b233
children 72e809e57ba4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
1 --- mongoose.c.orig 2019-01-14 13:06:27.147098524 +0100
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
2 +++ mongoose.c 2019-01-14 12:44:35.331361929 +0100
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 @@ -50,6 +50,14 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
4 #define PATH_MAX FILENAME_MAX
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
5 #endif // __SYMBIAN32__
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
6
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
7 +#if __gnu_hurd__ == 1
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
8 +/**
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
9 + * There is no limit on the length on a path under GNU Hurd, so we set
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
10 + * it to an arbitrary constant.
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
11 + **/
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
12 +#define PATH_MAX 4096
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
13 +#endif
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
14 +
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
15 #ifndef _WIN32_WCE // Some ANSI #includes are not available on Windows CE
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
16 #include <sys/types.h>
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
17 #include <sys/stat.h>
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 @@ -108,8 +116,9 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
19 #define strtoll(x, y, z) _atoi64(x)
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
20 #else
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
21 #define __func__ __FUNCTION__
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
22 -#define strtoull(x, y, z) _strtoui64(x, y, z)
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
23 -#define strtoll(x, y, z) _strtoi64(x, y, z)
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
24 +#include <stdlib.h>
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
25 +//#define strtoull(x, y, z) _strtoui64(x, y, z)
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
26 +//#define strtoll(x, y, z) _strtoi64(x, y, z)
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
27 #endif // _MSC_VER
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
28
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
29 #define ERRNO GetLastError()
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
30 @@ -2997,19 +3006,19 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
31 }
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
32 }
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
33
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
34 -static int is_valid_http_method(const char *method) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
35 - return !strcmp(method, "GET") || !strcmp(method, "POST") ||
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
36 +static int is_valid_http_method(const char *method, int *isValidHttpMethod) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
37 + *isValidHttpMethod = !strcmp(method, "GET") || !strcmp(method, "POST") ||
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
38 !strcmp(method, "HEAD") || !strcmp(method, "CONNECT") ||
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
39 !strcmp(method, "PUT") || !strcmp(method, "DELETE") ||
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
40 !strcmp(method, "OPTIONS") || !strcmp(method, "PROPFIND")
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
41 - || !strcmp(method, "MKCOL")
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
42 - ;
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
43 + || !strcmp(method, "MKCOL");
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
44 + return *isValidHttpMethod;
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
45 }
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
46
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
47 // Parse HTTP request, fill in mg_request_info structure.
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
48 // This function modifies the buffer by NUL-terminating
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
49 // HTTP request components, header names and header values.
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
50 -static int parse_http_message(char *buf, int len, struct mg_request_info *ri) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
51 +static int parse_http_message(char *buf, int len, struct mg_request_info *ri, int *isValidHttpMethod) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
52 int is_request, request_length = get_request_len(buf, len);
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
53 if (request_length > 0) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
54 // Reset attributes. DO NOT TOUCH is_ssl, remote_ip, remote_port
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
55 @@ -3025,7 +3034,7 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
56 ri->request_method = skip(&buf, " ");
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
57 ri->uri = skip(&buf, " ");
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
58 ri->http_version = skip(&buf, "\r\n");
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
59 - if (((is_request = is_valid_http_method(ri->request_method)) &&
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
60 + if (((is_request = is_valid_http_method(ri->request_method, isValidHttpMethod)) &&
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
61 memcmp(ri->http_version, "HTTP/", 5) != 0) ||
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
62 (!is_request && memcmp(ri->request_method, "HTTP/", 5)) != 0) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
63 request_length = -1;
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
64 @@ -4930,7 +4939,7 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
65 return uri[0] == '/' || (uri[0] == '*' && uri[1] == '\0');
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
66 }
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
67
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
68 -static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
69 +static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *isValidHttpMethod) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
70 const char *cl;
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
71
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
72 ebuf[0] = '\0';
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
73 @@ -4944,7 +4953,7 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
74 } else if (conn->request_len <= 0) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
75 snprintf(ebuf, ebuf_len, "%s", "Client closed connection");
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
76 } else if (parse_http_message(conn->buf, conn->buf_size,
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
77 - &conn->request_info) <= 0) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
78 + &conn->request_info, isValidHttpMethod) <= 0) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
79 snprintf(ebuf, ebuf_len, "Bad request: [%.*s]", conn->data_len, conn->buf);
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
80 } else {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
81 // Request is valid
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
82 @@ -4973,7 +4982,8 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
83 } else if (mg_vprintf(conn, fmt, ap) <= 0) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
84 snprintf(ebuf, ebuf_len, "%s", "Error sending request");
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
85 } else {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
86 - getreq(conn, ebuf, ebuf_len);
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
87 + int isValidHttpMethod = 1; /* unused in this case */
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
88 + getreq(conn, ebuf, ebuf_len, &isValidHttpMethod);
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
89 }
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
90 if (ebuf[0] != '\0' && conn != NULL) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
91 mg_close_connection(conn);
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
92 @@ -4995,8 +5005,13 @@
3373
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
93 // to crule42.
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
94 conn->data_len = 0;
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
95 do {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
96 - if (!getreq(conn, ebuf, sizeof(ebuf))) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
97 + int isValidHttpMethod = 1;
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
98 + if (!getreq(conn, ebuf, sizeof(ebuf), &isValidHttpMethod)) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
99 + if (isValidHttpMethod) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
100 send_http_error(conn, 500, "Server Error", "%s", ebuf);
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
101 + } else {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
102 + send_http_error(conn, 400, "Bad Request", "%s", ebuf);
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
103 + }
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
104 conn->must_close = 1;
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
105 } else if (!is_valid_uri(conn->request_info.uri)) {
4a8e8a96b233 Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 3119
diff changeset
106 snprintf(ebuf, sizeof(ebuf), "Invalid URI: [%s]", ri->uri);