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:
ari-ahm
2025-12-26 23:47:24 +03:30
committed by GitHub
parent 36968909a1
commit 6738ecf68e
3 changed files with 11 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -93,7 +93,7 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
if request.User = validator.Get(id); request.User == nil {
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 {