mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-08 09:32:06 +08:00
Fix panic on some stupid input
This commit is contained in:
parent
134802d1ee
commit
d8b2d5142f
@ -102,7 +102,10 @@ func NewDefaultRule(ctx context.Context, logger log.ContextLogger, options optio
|
|||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
|
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
|
||||||
item := NewDomainItem(options.Domain, options.DomainSuffix)
|
item, err := NewDomainItem(options.Domain, options.DomainSuffix)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,10 @@ func NewDefaultDNSRule(ctx context.Context, logger log.ContextLogger, options op
|
|||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
|
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
|
||||||
item := NewDomainItem(options.Domain, options.DomainSuffix)
|
item, err := NewDomainItem(options.Domain, options.DomainSuffix)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,10 @@ func NewDefaultHeadlessRule(ctx context.Context, options option.DefaultHeadlessR
|
|||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
|
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
|
||||||
item := NewDomainItem(options.Domain, options.DomainSuffix)
|
item, err := NewDomainItem(options.Domain, options.DomainSuffix)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
} else if options.DomainMatcher != nil {
|
} else if options.DomainMatcher != nil {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
"github.com/sagernet/sing/common/domain"
|
"github.com/sagernet/sing/common/domain"
|
||||||
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ RuleItem = (*DomainItem)(nil)
|
var _ RuleItem = (*DomainItem)(nil)
|
||||||
@ -14,7 +15,17 @@ type DomainItem struct {
|
|||||||
description string
|
description string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomainItem(domains []string, domainSuffixes []string) *DomainItem {
|
func NewDomainItem(domains []string, domainSuffixes []string) (*DomainItem, error) {
|
||||||
|
for _, domainItem := range domains {
|
||||||
|
if domainItem == "" {
|
||||||
|
return nil, E.New("domain: empty item is not allowed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, domainSuffixItem := range domainSuffixes {
|
||||||
|
if domainSuffixItem == "" {
|
||||||
|
return nil, E.New("domain_suffix: empty item is not allowed")
|
||||||
|
}
|
||||||
|
}
|
||||||
var description string
|
var description string
|
||||||
if dLen := len(domains); dLen > 0 {
|
if dLen := len(domains); dLen > 0 {
|
||||||
if dLen == 1 {
|
if dLen == 1 {
|
||||||
@ -40,7 +51,7 @@ func NewDomainItem(domains []string, domainSuffixes []string) *DomainItem {
|
|||||||
return &DomainItem{
|
return &DomainItem{
|
||||||
domain.NewMatcher(domains, domainSuffixes, false),
|
domain.NewMatcher(domains, domainSuffixes, false),
|
||||||
description,
|
description,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRawDomainItem(matcher *domain.Matcher) *DomainItem {
|
func NewRawDomainItem(matcher *domain.Matcher) *DomainItem {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user