Skip to content

syscall: unix Sendto panic if nil Sockaddr provided #55845

@nathanaelle

Description

@nathanaelle

What version of Go are you using (go version)?

1.19.1

Does this issue reproduce with the latest release?

yes.

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

ubuntu linux 22.04 on amd64

What did you do?

syscall.Sendto(socket, buffer, flag, nil)

What did you expect to see?

as specified in https://linux.die.net/man/2/sendto

send(sockfd, buf, len, flags);

is equivalent to

sendto(sockfd, buf, len, flags, NULL, 0); 

What did you see instead?

we can see in https://cs.opensource.google/go/go/+/refs/tags/go1.19.1:src/syscall/syscall_unix.go;l=445

func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error) {
	ptr, n, err := to.sockaddr()
	if err != nil {
		return err
	}
	return sendto(fd, p, flags, ptr, n)
}

the nil situation for to is not tested, thus a panic() occurs.

Suggestion

is it possible to add a test to avoid a panic() when to is set to nil like in SendmsgN() ( see: https://cs.opensource.google/go/go/+/refs/tags/go1.19.1:src/syscall/syscall_unix.go;l=400 ) ?

this issue may also impact :
– SendtoInet4
– SendtoInet6
– SendmsgNInet4
– SendmsgNInet6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions