]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/http: make sure uv_handle is always initialized
authorTomas Krizek <tomas.krizek@nic.cz>
Thu, 1 Oct 2020 12:09:47 +0000 (14:09 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 13 Oct 2020 10:55:29 +0000 (12:55 +0200)
It is later closed in endpoint_close(), which would fail with assert if
not initialized (e.g. when compiled without nghttp2 support and
attempting to use doh2 kind).

daemon/io.c

index f64ead4f8d5206b44bf190cd22f5970adaac8f03..ce4c46df6546a0cbce8f8b420b94771abe1533ae 100644 (file)
@@ -497,11 +497,18 @@ static void https_accept(uv_stream_t *master, int status)
 int io_listen_tcp(uv_loop_t *loop, uv_tcp_t *handle, int fd, int tcp_backlog, bool has_tls, bool has_http)
 {
        uv_connection_cb connection;
+
+       if (!handle) {
+               return kr_error(EINVAL);
+       }
+       int ret = uv_tcp_init(loop, handle);
+       if (ret) return ret;
+
        if (has_tls && has_http) {
 #ifdef ENABLE_DOH2
                connection = https_accept;
 #else
-               kr_log_error("[ io ] kresd was compiled without libnghttp2 support");
+               kr_log_error("[ io ] kresd was compiled without libnghttp2 support\n");
                return kr_error(ENOPROTOOPT);
 #endif
        } else if (has_tls) {
@@ -512,12 +519,6 @@ int io_listen_tcp(uv_loop_t *loop, uv_tcp_t *handle, int fd, int tcp_backlog, bo
                connection = tcp_accept;
        }
 
-       if (!handle) {
-               return kr_error(EINVAL);
-       }
-       int ret = uv_tcp_init(loop, handle);
-       if (ret) return ret;
-
        ret = uv_tcp_open(handle, (uv_os_sock_t) fd);
        if (ret) return ret;