Sfoglia il codice sorgente

fix: fix http3 crash when free stream

Nick Peng 2 settimane fa
parent
commit
0fcba50292

+ 1 - 0
src/dns_client/client_http2.c

@@ -196,6 +196,7 @@ int _dns_client_send_http2(struct dns_server_info *server_info, struct dns_query
 		tlog(TLOG_ERROR, "malloc memory failed for http2 stream.");
 		return -1;
 	}
+	stream->type = DNS_SERVER_HTTPS;
 
 	/* Link stream to server and query */
 	pthread_mutex_lock(&server_info->lock);

+ 1 - 0
src/dns_client/client_quic.c

@@ -631,6 +631,7 @@ int _dns_client_send_quic_data(struct dns_query_struct *query, struct dns_server
 		tlog(TLOG_ERROR, "malloc memory failed.");
 		return -1;
 	}
+	stream->type = server_info->type;
 
 	if (server_info->status != DNS_SERVER_STATUS_CONNECTED) {
 		ret = _dns_client_quic_pending_data(stream, server_info, query, packet, len);

+ 26 - 21
src/dns_client/conn_stream.c

@@ -57,17 +57,19 @@ void _dns_client_conn_stream_put(struct dns_conn_stream *stream)
 		return;
 	}
 
-	/* Clean up QUIC stream */
-	if (stream->quic_stream) {
-		SSL_free(stream->quic_stream);
-		stream->quic_stream = NULL;
-	}
-
-	/* Clean up HTTP/2 stream */
-	if (stream->http2_stream) {
-		struct http2_stream *http2_stream = stream->http2_stream;
-		stream->http2_stream = NULL;
-		http2_stream_put(http2_stream);
+	if (stream->type == DNS_SERVER_QUIC || stream->type == DNS_SERVER_HTTP3) {
+		/* Clean up QUIC stream */
+		if (stream->quic_stream) {
+			SSL_free(stream->quic_stream);
+			stream->quic_stream = NULL;
+		}
+	} else if (stream->type == DNS_SERVER_HTTPS) {
+		/* Clean up HTTP/2 stream */
+		if (stream->http2_stream) {
+			struct http2_stream *http2_stream = stream->http2_stream;
+			stream->http2_stream = NULL;
+			http2_stream_put(http2_stream);
+		}
 	}
 
 	if (stream->query) {
@@ -101,18 +103,21 @@ void _dns_client_conn_server_streams_free(struct dns_server_info *server_info, s
 
 		list_del_init(&stream->server_list);
 		stream->server_info = NULL;
-		if (stream->quic_stream) {
+		if (stream->type == DNS_SERVER_QUIC || stream->type == DNS_SERVER_HTTP3) {
+			if (stream->quic_stream) {
 #if defined(OSSL_QUIC1_VERSION) && !defined(OPENSSL_NO_QUIC)
-			SSL_stream_reset(stream->quic_stream, NULL, 0);
+				SSL_stream_reset(stream->quic_stream, NULL, 0);
 #endif
-			SSL_free(stream->quic_stream);
-			stream->quic_stream = NULL;
-		}
-		/* Clean up HTTP/2 stream */
-		if (stream->http2_stream) {
-			struct http2_stream *http2_stream = stream->http2_stream;
-			stream->http2_stream = NULL;
-			http2_stream_put(http2_stream);
+				SSL_free(stream->quic_stream);
+				stream->quic_stream = NULL;
+			}
+		} else if (stream->type == DNS_SERVER_HTTPS) {
+			/* Clean up HTTP/2 stream */
+			if (stream->http2_stream) {
+				struct http2_stream *http2_stream = stream->http2_stream;
+				stream->http2_stream = NULL;
+				http2_stream_put(http2_stream);
+			}
 		}
 		_dns_client_conn_stream_put(stream);
 	}

+ 1 - 0
src/dns_client/dns_client.h

@@ -234,6 +234,7 @@ struct dns_conn_stream {
 		SSL *quic_stream;
 		struct http2_stream *http2_stream;
 	};
+	dns_server_type_t type;
 };
 
 /* query struct */