-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check socket address size #152
Conversation
💚 CLA has been signed |
fb99068
to
874245e
Compare
It sounds like we should add that fuzz test into auparse/sockaddr_test.go. WDYT @Cravtos? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add an entry into the changelog at:
Line 10 in 5216c76
### Changed |
The code changes LGTM.
Added fuzz test and updated changelog: b5915b8. |
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but needs an additional reviewer because I pushed a gofumpt
change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but nit.
auparse/sockaddr.go
Outdated
"strconv" | ||
) | ||
|
||
// errInvalidSockAddrSize means socket address size is invalid. | ||
var errInvalidSockAddrSize = errors.New("invalid socket address size") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if the errors returned included the family and the len of the provided address.
type invalidSockAddrErr struct {
family string
size int
}
func (e invalidSockAddrErr) Error() string {
return fmt.Sprintf("invalid socket address size family=%s: %d, e.family, e.size)
}
populated appropriately below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What family to specify in case of len(sockAddr) < 4
? Or it would be better to introduce another error type for malformed families? Like so:
type invalidSockFamilyError struct {
family string
}
func (e invalidSockFamilyError) Error() string {
return fmt.Sprintf("invalid socket address family=%s", e.family)
}
// ...
if len(s) < 4 {
return nil, invalidSockFamilyError{
family: s,
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest either calling the family "invalid", or conditionally format an error in the Error
method when the size is less than 4 and don't use the family
field in that case.
type invalidSockAddrErr struct {
family string
size int
}
func (e invalidSockAddrErr) Error() string {
if e.size < 4 {
return fmt.Sprintf("invalid family: too short: %d", e.size)
}
return fmt.Sprintf("invalid socket address size family=%s: %d, e.family, e.size)
}
and in the preamble of the func,
func parseSockaddr(s string) (map[string]string, error) {
if len(s) < 4 {
return nil, invalidSockAddrErr{size: len(s)}
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: b1c5994
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but waiting for @andrewkroh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for the contribution.
In auparse.parseSockaddr(), check socket address size before indexing into the slice to prevent panics. Return an error detailing the failure. Add a Go fuzz test to exercise the parseSockaddr() function.
Fixes panic when malformed socket address is parsed (e.g. during fuzz testing).