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()
|
||||
|
||||
for _, byteGroup := range byteGroups {
|
||||
if text[0] == '-' {
|
||||
if len(text) > 0 && text[0] == '-' {
|
||||
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 {
|
||||
return uuid, err
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ func TestParseString(t *testing.T) {
|
||||
if err == 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) {
|
||||
|
||||
Reference in New Issue
Block a user