Pārlūkot izejas kodu

refactor: use `math.MaxUint16` when checking port

Shishkevich D. 1 dienu atpakaļ
vecāks
revīzija
f86219f4de
2 mainītis faili ar 5 papildinājumiem un 3 dzēšanām
  1. 3 2
      web/entity/entity.go
  2. 2 1
      xray/api.go

+ 3 - 2
web/entity/entity.go

@@ -5,6 +5,7 @@ import (
 	"net"
 	"strings"
 	"time"
+	"math"
 
 	"x-ui/util/common"
 )
@@ -78,11 +79,11 @@ func (s *AllSetting) CheckValid() error {
 		}
 	}
 
-	if s.WebPort <= 0 || s.WebPort > 65535 {
+	if s.WebPort <= 0 || s.WebPort > math.MaxUint16 {
 		return common.NewError("web port is not a valid port:", s.WebPort)
 	}
 
-	if s.SubPort <= 0 || s.SubPort > 65535 {
+	if s.SubPort <= 0 || s.SubPort > math.MaxUint16 {
 		return common.NewError("Sub port is not a valid port:", s.SubPort)
 	}
 

+ 2 - 1
xray/api.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"regexp"
 	"time"
+	"math"
 
 	"x-ui/logger"
 	"x-ui/util/common"
@@ -32,7 +33,7 @@ type XrayAPI struct {
 }
 
 func (x *XrayAPI) Init(apiPort int) error {
-	if apiPort <= 0 {
+	if apiPort <= 0 || apiPort > math.MaxUint16 {
 		return fmt.Errorf("invalid Xray API port: %d", apiPort)
 	}