1 | // Test that ASan doesn't raise false alarm when getsockname and getpeername |
2 | // are called with addrlen=nullptr; |
3 | // |
4 | // RUN: %clangxx %s -o %t && %run %t 2>&1 |
5 | |
6 | #include <assert.h> |
7 | #include <errno.h> |
8 | #include <netinet/in.h> |
9 | #include <sys/socket.h> |
10 | |
11 | int main() { |
12 | const int fd = socket(AF_INET, SOCK_DGRAM, protocol: 0); |
13 | assert(fd >= 0); |
14 | |
15 | const sockaddr_in sin = { |
16 | .sin_family = AF_INET, |
17 | .sin_port = htons(hostshort: 1234), |
18 | .sin_addr = |
19 | { |
20 | .s_addr = htonl(INADDR_LOOPBACK), |
21 | }, |
22 | }; |
23 | assert(connect(fd, reinterpret_cast<const sockaddr *>(&sin), sizeof(sin)) == |
24 | 0); |
25 | |
26 | errno = 0; |
27 | assert(getsockname(fd, nullptr, nullptr) == -1); |
28 | assert(errno == EFAULT); |
29 | |
30 | errno = 0; |
31 | assert(getpeername(fd, nullptr, nullptr) == -1); |
32 | assert(errno == EFAULT); |
33 | |
34 | return 0; |
35 | } |
36 | |