Skip to content
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

Merged
merged 4 commits into from
May 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions auparse/sockaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@
package auparse

import (
"errors"
"strconv"
)

var (
// errInvalidSockAddrSize means socket address size is invalid.
errInvalidSockAddrSize = errors.New("invalid socket address size")
)

func parseSockaddr(s string) (map[string]string, error) {
if len(s) < 4 {
return nil, errInvalidSockAddrSize
}

addressFamily, err := hexToDec(s[2:4] + s[0:2]) // host-order
if err != nil {
return nil, err
Expand All @@ -38,6 +48,10 @@ func parseSockaddr(s string) (map[string]string, error) {
out["family"] = "unix"
out["path"] = socket
case 2: // AF_INET
if len(s) < 16 {
return nil, errInvalidSockAddrSize
}

port, err := hexToDec(s[4:8])
if err != nil {
return nil, err
Expand All @@ -52,6 +66,10 @@ func parseSockaddr(s string) (map[string]string, error) {
out["addr"] = ip
out["port"] = strconv.Itoa(int(port))
case 10: // AF_INET6
if len(s) < 48 {
return nil, errInvalidSockAddrSize
}

port, err := hexToDec(s[4:8])
if err != nil {
return nil, err
Expand Down