Skip to content

Commit 6738ecf

Browse files
authored
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
1 parent 3696890 commit 6738ecf

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

common/uuid/uuid.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ func ParseString(str string) (UUID, error) {
8585
b := uuid.Bytes()
8686

8787
for _, byteGroup := range byteGroups {
88-
if text[0] == '-' {
88+
if len(text) > 0 && text[0] == '-' {
8989
text = text[1:]
9090
}
9191

92+
if len(text) < byteGroup {
93+
return uuid, errors.New("invalid UUID: ", str)
94+
}
95+
9296
if _, err := hex.Decode(b[:byteGroup/2], text[:byteGroup]); err != nil {
9397
return uuid, err
9498
}

common/uuid/uuid_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ func TestParseString(t *testing.T) {
4444
if err == nil {
4545
t.Fatal("Expect error but nil")
4646
}
47+
48+
_, err = ParseString("2418d087-648d-4990-86e8-19dca1d0")
49+
if err == nil {
50+
t.Fatal("Expect error but nil")
51+
}
4752
}
4853

4954
func TestNewUUID(t *testing.T) {

proxy/vless/encoding/encoding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
9393

9494
if request.User = validator.Get(id); request.User == nil {
9595
u := uuid.UUID(id)
96-
return nil, nil, nil, isfb, errors.New("invalid request user id: %s" + u.String())
96+
return nil, nil, nil, isfb, errors.New("invalid request user id: " + u.String())
9797
}
9898

9999
if isfb {

0 commit comments

Comments
 (0)