From 83686ebfaa56666b7cf95d31cc53990ef9c57e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Sat, 19 Jul 2025 09:43:06 +0800 Subject: [PATCH] DNS outbound: Prevent panic from rejecting invalid domain (#4903) Fixes https://github.com/XTLS/Xray-core/pull/4824#issuecomment-3078811352 --- proxy/dns/dns.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/proxy/dns/dns.go b/proxy/dns/dns.go index a35854ef..0f83f5ac 100644 --- a/proxy/dns/dns.go +++ b/proxy/dns/dns.go @@ -338,11 +338,16 @@ func (h *Handler) rejectNonIPQuery(id uint16, qType dnsmessage.Type, domain stri }) builder.EnableCompression() common.Must(builder.StartQuestions()) - common.Must(builder.Question(dnsmessage.Question{ + err := builder.Question(dnsmessage.Question{ Name: dnsmessage.MustNewName(domain), Class: dnsmessage.ClassINET, Type: qType, - })) + }) + if err != nil { + errors.LogInfo(context.Background(), "unexpected domain ", domain, " when building reject message: ", err) + b.Release() + return + } msgBytes, err := builder.Finish() if err != nil {