From ca9fe3559a1e369ee4bf698f5c5f5417258cd8bc Mon Sep 17 00:00:00 2001 From: Artem Boldariev Date: Fri, 14 Jan 2022 14:14:53 +0200 Subject: [PATCH] DoH: ensure that server_send_error_response() is used properly The server_send_error_response() function is supposed to be used only in case of failures and never in case of legitimate requests. Ensure that ISC_HTTP_ERROR_SUCCESS is never passed there by mistake. --- lib/isc/netmgr/http.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index 5427756a23..0d06c1b902 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -1941,7 +1941,6 @@ static struct http_error_responses { const nghttp2_nv header; const char *desc; } error_responses[] = { - MAKE_ERROR_REPLY(ISC_HTTP_ERROR_SUCCESS, 200, "OK"), MAKE_ERROR_REPLY(ISC_HTTP_ERROR_BAD_REQUEST, 400, "Bad Request"), MAKE_ERROR_REPLY(ISC_HTTP_ERROR_NOT_FOUND, 404, "Not Found"), MAKE_ERROR_REPLY(ISC_HTTP_ERROR_PAYLOAD_TOO_LARGE, 413, @@ -1979,7 +1978,11 @@ log_server_error_response(const isc_nmsocket_t *socket, static isc_result_t server_send_error_response(const isc_http_error_responses_t error, nghttp2_session *ngsession, isc_nmsocket_t *socket) { - void *base = isc_buffer_base(&socket->h2.rbuf); + void *base; + + REQUIRE(error != ISC_HTTP_ERROR_SUCCESS); + + base = isc_buffer_base(&socket->h2.rbuf); if (base != NULL) { isc_mem_free(socket->h2.session->mctx, base); isc_buffer_initnull(&socket->h2.rbuf);