Skip to content

Commit

Permalink
Check socket address size
Browse files Browse the repository at this point in the history
  • Loading branch information
Cravtos committed May 15, 2024
1 parent 5216c76 commit fb99068
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit fb99068

Please sign in to comment.