1
0
mirror of https://github.com/golang/go synced 2024-11-17 22:14:43 -07:00

syscall: validate ParseUnixCredentials inputs

Don't panic, crash, or return references to uninitialized memory when
ParseUnixCredentials is passed invalid input.

Fixes #16475

Change-Id: I140d41612e8cd8caaa94be829a415159659c217b
Reviewed-on: https://go-review.googlesource.com/25154
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Gudger 2016-07-22 16:38:27 -07:00 committed by Brad Fitzpatrick
parent fa897643a1
commit 7995cb86e5

View File

@ -31,6 +31,9 @@ func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) {
if m.Header.Type != SCM_CREDENTIALS {
return nil, EINVAL
}
if uintptr(len(m.Data)) < unsafe.Sizeof(Ucred{}) {
return nil, EINVAL
}
ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0]))
return &ucred, nil
}