DNS outbound: Prevent panic from rejecting invalid domain (#4903)

Fixes https://github.com/XTLS/Xray-core/pull/4824#issuecomment-3078811352
This commit is contained in:
风扇滑翔翼 2025-07-19 09:43:06 +08:00 committed by RPRX
parent 79c6f99384
commit 83686ebfaa

View file

@ -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 {