[PATCH uhttpd] client: Always close connection with request body in case of error
Hauke Mehrtens
hauke at hauke-m.de
Sat Mar 20 19:37:38 GMT 2021
On 3/20/21 8:28 PM, Hauke Mehrtens wrote:
> When we run into an error like a 404 Not Found the request body is not
> read and will be parsed as part of the next request. The next Request
> will then fail because there is unexpected data in it.
> When we run into such a problem with a request body close return an
> error and close the connection. This should be easier than trying to
> recover the state.
>
> We saw this problem when /ubus/ was not installed, but the browser tried
> to access it. Then uhttpd returned a 404, but the next request done in
> this connection also failed with a HTTP 400, bad request.
>
> Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
This should fix the following bug report:
https://bugs.openwrt.org/index.php?do=details&task_id=3378
> ---
> client.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/client.c b/client.c
> index 6233d01..1d337f3 100644
> --- a/client.c
> +++ b/client.c
> @@ -138,6 +138,7 @@ void uh_request_done(struct client *cl)
> void __printf(4, 5)
> uh_client_error(struct client *cl, int code, const char *summary, const char *fmt, ...)
> {
> + struct http_request *r = &cl->request;
> va_list arg;
>
> uh_http_header(cl, code, summary);
> @@ -151,6 +152,11 @@ uh_client_error(struct client *cl, int code, const char *summary, const char *fm
> va_end(arg);
> }
>
> + if (r->transfer_chunked || r->content_length > 0) {
> + cl->state = CLIENT_STATE_CLOSE;
> + cl->request.connection_close = true;
> + }
> +
> uh_request_done(cl);
> }
>
>
More information about the openwrt-devel
mailing list