libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 66e6f4f2e965682d1cabaf217d6db40beb0877e1
parent 4fb57ae153ddd856c80885425eb2321cd95a2cf0
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 21 Aug 2021 18:28:35 +0300

connection.c: simplified request line processing, fix

Fixed potential hung when the first line is empty and no
other connections are processed.

Diffstat:
Msrc/microhttpd/connection.c | 42++++++++++++++++++++----------------------
1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -4104,34 +4104,32 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) case MHD_CONNECTION_INIT: line = get_next_header_line (connection, &line_len); - /* Check for empty string, as we might want - to tolerate 'spurious' empty lines; also - NULL means we didn't get a full line yet; - line is not 0-terminated here. */ - if ( (NULL == line) || - (0 == line[0]) ) + if (NULL != line) { - if (MHD_CONNECTION_INIT != connection->state) - continue; - if (connection->stop_with_error) + /* Check for empty string, as we might want + to tolerate 'spurious' empty lines */ + if (0 == line[0]) + /* TODO: Add MHD option to not tolerate it */ + continue; /* Process the next line */ + if (MHD_NO == parse_initial_message_line (connection, + line, + line_len)) + CONNECTION_CLOSE_ERROR_CHECK (connection, + NULL); + else { - CONNECTION_CLOSE_ERROR (connection, - NULL); - continue; + mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver)); + connection->state = MHD_CONNECTION_URL_RECEIVED; } - break; + continue; } - if (MHD_NO == parse_initial_message_line (connection, - line, - line_len)) - CONNECTION_CLOSE_ERROR_CHECK (connection, - NULL); - else + /* NULL means we didn't get a full line yet */ + if (connection->stop_with_error) { - mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver)); - connection->state = MHD_CONNECTION_URL_RECEIVED; + mhd_assert (MHD_CONNECTION_INIT != connection->state); + continue; } - continue; + break; case MHD_CONNECTION_URL_RECEIVED: line = get_next_header_line (connection, NULL);