Description
When getpeername() is called on a socket that is not connected and has no pre-specified peer, it returns 0 instead of
failing with -1 and setting errno to ENOTCONN.
Expected behavior
getpeername() shall fail with ENOTCONN when the socket is not connected or otherwise has not had the peer pre-specified.
Actual behavior
getpeername() returns 0 and does not set errno.
Observed output:
getpeername(unconnected): ret=0 errno=0 (EOK)
POSIX requirement (if applicable)
POSIX.1-2017 (IEEE Std 1003.1-2017), getpeername(3p), section ERRORS:
"[ENOTCONN] The socket is not connected or otherwise has not had the peer pre-specified."
Minimal reproduction code
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
int main(void)
{
int fd, ret;
struct sockaddr_un peer;
socklen_t len = sizeof(peer);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
errno = 0;
ret = getpeername(fd, (struct sockaddr *)&peer, &len);
printf("getpeername(unconnected): ret=%d errno=%d (%s)\n", ret, errno, strerror(errno));
close(fd);
return 0;
}
Host behavior
getpeername(unconnected): ret=-1 errno=107 (Transport endpoint is not connected)
Revision
Discovered on 62b46f9
Target
Reproduced on ia32-generic-qemu, not tested on other targets yet.
Related tests
phoenix-rtos-tests/libc/socket/getpeername.c
These tests are currently skipped on the affected target. After applying a fix, re-enable them and re-run the suite to
verify the fix.
Description
When
getpeername()is called on a socket that is not connected and has no pre-specified peer, it returns0instead offailing with
-1and settingerrnotoENOTCONN.Expected behavior
getpeername()shall fail withENOTCONNwhen the socket is not connected or otherwise has not had the peer pre-specified.Actual behavior
getpeername()returns0and does not seterrno.Observed output:
POSIX requirement (if applicable)
POSIX.1-2017 (IEEE Std 1003.1-2017), getpeername(3p), section ERRORS:
"[ENOTCONN] The socket is not connected or otherwise has not had the peer pre-specified."
Minimal reproduction code
Host behavior
Revision
Discovered on 62b46f9
Target
Reproduced on ia32-generic-qemu, not tested on other targets yet.
Related tests
phoenix-rtos-tests/libc/socket/getpeername.cThese tests are currently skipped on the affected target. After applying a fix, re-enable them and re-run the suite to
verify the fix.