Fix: potential panic in putMsgToCache (#2634)
When the upstream DNS server returns a message that contains no questions (i.e. QDCOUNT == 0), `putMsgToCache` will trigger an out-of-range panic. Issue: #2524 Comment: https://github.com/Dreamacro/clash/issues/2524#issuecomment-1477477601
This commit is contained in:
parent
d808576f98
commit
8f9b39c62e
@ -162,7 +162,7 @@ func (r *Resolver) exchangeWithoutCache(ctx context.Context, m *D.Msg) (msg *D.M
|
|||||||
|
|
||||||
msg := result.(*D.Msg)
|
msg := result.(*D.Msg)
|
||||||
|
|
||||||
putMsgToCache(r.lruCache, q.String(), msg)
|
putMsgToCache(r.lruCache, q.String(), q, msg)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
isIPReq := isIPRequest(q)
|
isIPReq := isIPRequest(q)
|
||||||
|
@ -16,9 +16,9 @@ import (
|
|||||||
D "github.com/miekg/dns"
|
D "github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func putMsgToCache(c *cache.LruCache, key string, msg *D.Msg) {
|
func putMsgToCache(c *cache.LruCache, key string, q D.Question, msg *D.Msg) {
|
||||||
// skip dns cache for acme challenge
|
// skip dns cache for acme challenge
|
||||||
if q := msg.Question[0]; q.Qtype == D.TypeTXT && strings.HasPrefix(q.Name, "_acme-challenge") {
|
if q.Qtype == D.TypeTXT && strings.HasPrefix(q.Name, "_acme-challenge.") {
|
||||||
log.Debugln("[DNS] dns cache ignored because of acme challenge for: %s", q.Name)
|
log.Debugln("[DNS] dns cache ignored because of acme challenge for: %s", q.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user