Skip to content

x/sys/unix: syscall_unix.go - Recvmsg reports empty/wrong error value #58898

@rinor

Description

@rinor

Does this issue reproduce with the latest release?

  • yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOVERSION="go1.20.1"

What did you do?

import (
	"golang.org/x/sys/unix"
)
...
retn, _, _, _, err = unix.Recvmsg(tunfd, msg[:], nil, 0)

What did you expect to see?

retn == -1
err != nil

What did you see instead?

retn == -1
err == nil

https://github.com/golang/sys/blob/494aa493ccb0c797af52f75ff7839a241bb26cdd/unix/syscall_unix.go#L356 is lacking error check

	n, oobn, recvflags, err = recvmsgRaw(fd, iov[:], oob, flags, &rsa)
	if rsa.Addr.Family != AF_UNSPEC {
		from, err = anyToSockaddr(fd, &rsa)
	}

vs

	n, oobn, recvflags, err = recvmsgRaw(fd, iov[:], oob, flags, &rsa)
	if err == nil && rsa.Addr.Family != AF_UNSPEC {
		from, err = anyToSockaddr(fd, &rsa)
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions