diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-08-21 18:28:35 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-08-21 18:35:21 +0300 |
commit | 66e6f4f2e965682d1cabaf217d6db40beb0877e1 (patch) | |
tree | 7da14dd5b2e81e891b2b9d222437ce6d6ea40b1d | |
parent | 4fb57ae153ddd856c80885425eb2321cd95a2cf0 (diff) | |
download | libmicrohttpd-66e6f4f2e965682d1cabaf217d6db40beb0877e1.tar.gz libmicrohttpd-66e6f4f2e965682d1cabaf217d6db40beb0877e1.zip |
connection.c: simplified request line processing, fix
Fixed potential hung when the first line is empty and no
other connections are processed.
-rw-r--r-- | src/microhttpd/connection.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 7b61916f..2ee1ceb2 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -4104,34 +4104,32 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4104 | case MHD_CONNECTION_INIT: | 4104 | case MHD_CONNECTION_INIT: |
4105 | line = get_next_header_line (connection, | 4105 | line = get_next_header_line (connection, |
4106 | &line_len); | 4106 | &line_len); |
4107 | /* Check for empty string, as we might want | 4107 | if (NULL != line) |
4108 | to tolerate 'spurious' empty lines; also | ||
4109 | NULL means we didn't get a full line yet; | ||
4110 | line is not 0-terminated here. */ | ||
4111 | if ( (NULL == line) || | ||
4112 | (0 == line[0]) ) | ||
4113 | { | 4108 | { |
4114 | if (MHD_CONNECTION_INIT != connection->state) | 4109 | /* Check for empty string, as we might want |
4115 | continue; | 4110 | to tolerate 'spurious' empty lines */ |
4116 | if (connection->stop_with_error) | 4111 | if (0 == line[0]) |
4112 | /* TODO: Add MHD option to not tolerate it */ | ||
4113 | continue; /* Process the next line */ | ||
4114 | if (MHD_NO == parse_initial_message_line (connection, | ||
4115 | line, | ||
4116 | line_len)) | ||
4117 | CONNECTION_CLOSE_ERROR_CHECK (connection, | ||
4118 | NULL); | ||
4119 | else | ||
4117 | { | 4120 | { |
4118 | CONNECTION_CLOSE_ERROR (connection, | 4121 | mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver)); |
4119 | NULL); | 4122 | connection->state = MHD_CONNECTION_URL_RECEIVED; |
4120 | continue; | ||
4121 | } | 4123 | } |
4122 | break; | 4124 | continue; |
4123 | } | 4125 | } |
4124 | if (MHD_NO == parse_initial_message_line (connection, | 4126 | /* NULL means we didn't get a full line yet */ |
4125 | line, | 4127 | if (connection->stop_with_error) |
4126 | line_len)) | ||
4127 | CONNECTION_CLOSE_ERROR_CHECK (connection, | ||
4128 | NULL); | ||
4129 | else | ||
4130 | { | 4128 | { |
4131 | mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver)); | 4129 | mhd_assert (MHD_CONNECTION_INIT != connection->state); |
4132 | connection->state = MHD_CONNECTION_URL_RECEIVED; | 4130 | continue; |
4133 | } | 4131 | } |
4134 | continue; | 4132 | break; |
4135 | case MHD_CONNECTION_URL_RECEIVED: | 4133 | case MHD_CONNECTION_URL_RECEIVED: |
4136 | line = get_next_header_line (connection, | 4134 | line = get_next_header_line (connection, |
4137 | NULL); | 4135 | NULL); |