Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sanitizer] Allow getsockname with NULL addrlen
This is already permitted in getpeername, and returns EFAULT on Linux (does not crash the program). Fixes google/sanitizers#1451. Differential Revision: https://reviews.llvm.org/D113055
- Loading branch information
Showing
2 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
compiler-rt/test/sanitizer_common/TestCases/Linux/get_sock_peer_name.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Test that ASan doesn't raise false alarm when getsockname and getpeername | ||
// are called with addrlen=nullptr; | ||
// | ||
// RUN: %clangxx %s -o %t && %run %t 2>&1 | ||
|
||
#include <assert.h> | ||
#include <errno.h> | ||
#include <netinet/in.h> | ||
#include <sys/socket.h> | ||
|
||
int main() { | ||
const int fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
assert(fd >= 0); | ||
|
||
const sockaddr_in sin = { | ||
.sin_family = AF_INET, | ||
.sin_port = 1234, | ||
.sin_addr = | ||
{ | ||
.s_addr = INADDR_LOOPBACK, | ||
}, | ||
}; | ||
assert(connect(fd, reinterpret_cast<const sockaddr *>(&sin), sizeof(sin)) == | ||
0); | ||
|
||
errno = 0; | ||
assert(getsockname(fd, nullptr, nullptr) == -1); | ||
assert(errno == EFAULT); | ||
|
||
errno = 0; | ||
assert(getpeername(fd, nullptr, nullptr) == -1); | ||
assert(errno == EFAULT); | ||
|
||
return 0; | ||
} |