mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-08 14:13:22 +00:00
common/uuid: fix panic when parsing 32-len invalid UUID string. (#5468)
* common/uuid: fix panic when parsing 32-len invalid UUID string. * fix: removed typo
This commit is contained in:
@@ -85,10 +85,14 @@ func ParseString(str string) (UUID, error) {
|
|||||||
b := uuid.Bytes()
|
b := uuid.Bytes()
|
||||||
|
|
||||||
for _, byteGroup := range byteGroups {
|
for _, byteGroup := range byteGroups {
|
||||||
if text[0] == '-' {
|
if len(text) > 0 && text[0] == '-' {
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(text) < byteGroup {
|
||||||
|
return uuid, errors.New("invalid UUID: ", str)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := hex.Decode(b[:byteGroup/2], text[:byteGroup]); err != nil {
|
if _, err := hex.Decode(b[:byteGroup/2], text[:byteGroup]); err != nil {
|
||||||
return uuid, err
|
return uuid, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ func TestParseString(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expect error but nil")
|
t.Fatal("Expect error but nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = ParseString("2418d087-648d-4990-86e8-19dca1d0")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expect error but nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewUUID(t *testing.T) {
|
func TestNewUUID(t *testing.T) {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
|
|||||||
|
|
||||||
if request.User = validator.Get(id); request.User == nil {
|
if request.User = validator.Get(id); request.User == nil {
|
||||||
u := uuid.UUID(id)
|
u := uuid.UUID(id)
|
||||||
return nil, nil, nil, isfb, errors.New("invalid request user id: %s" + u.String())
|
return nil, nil, nil, isfb, errors.New("invalid request user id: " + u.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
if isfb {
|
if isfb {
|
||||||
|
|||||||
Reference in New Issue
Block a user