libc fortify: make socket.h and stdlib.h use diagnose_if
Since realpath no longer needs to be overloaded, we can restore the
upstream source to purity. We'll be able to do this with most of the
other functions when we pull a newer clang in.
Bug: 12231437
Test: m checkbuild on bionic internal master; CtsBionicTestCases show
no new failures.
Change-Id: I484221bba0b291273fece23d2be2f5f9fd713d2c
diff --git a/tests/fortify_compilation_test.cpp b/tests/fortify_compilation_test.cpp
index bb2b770..aab71a1 100644
--- a/tests/fortify_compilation_test.cpp
+++ b/tests/fortify_compilation_test.cpp
@@ -183,11 +183,20 @@
sockaddr_in addr;
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: error: call to '__recvfrom_error' declared with attribute error: recvfrom called with size bigger than buffer
- // CLANG: error: call to unavailable function 'recvfrom': recvfrom called with size bigger than buffer
+ // GCC: error: call to '__recvfrom_error' declared with attribute error: 'recvfrom' called with size bigger than buffer
+ // CLANG: error: 'recvfrom' called with size bigger than buffer
recvfrom(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), NULL);
}
+void test_recv() {
+ char buf[4] = {0};
+
+ // NOLINTNEXTLINE(whitespace/line_length)
+ // GCC: error: call to '__recvfrom_error' declared with attribute error: 'recvfrom' called with size bigger than buffer
+ // CLANG: error: 'recv' called with size bigger than buffer
+ recv(0, buf, 6, 0);
+}
+
void test_umask() {
// NOLINTNEXTLINE(whitespace/line_length)
// GCC: error: call to '__umask_invalid_mode' declared with attribute error: umask called with invalid mode
@@ -316,8 +325,8 @@
sockaddr_in addr;
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: error: call to '__sendto_error' declared with attribute error: sendto called with size bigger than buffer
- // CLANG: error: call to unavailable function 'sendto': sendto called with size bigger than buffer
+ // GCC: error: call to '__sendto_error' declared with attribute error: 'sendto' called with size bigger than buffer
+ // CLANG: error: 'sendto' called with size bigger than buffer
sendto(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), sizeof(sockaddr_in));
}
@@ -325,7 +334,22 @@
char buf[4] = {0};
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: error: call to '__sendto_error' declared with attribute error: sendto called with size bigger than buffer
- // CLANG: error: call to unavailable function 'send': send called with size bigger than buffer
+ // GCC: error: call to '__sendto_error' declared with attribute error: 'sendto' called with size bigger than buffer
+ // CLANG: error: 'send' called with size bigger than buffer
send(0, buf, 6, 0);
}
+
+void test_realpath() {
+ char buf[4] = {0};
+ // NOLINTNEXTLINE(whitespace/line_length)
+ // GCC: error: call to '__realpath_size_error' declared with attribute error: 'realpath' output parameter must be NULL or a pointer to a buffer with >= PATH_MAX bytes
+ // NOLINTNEXTLINE(whitespace/line_length)
+ // CLANG: error: 'realpath' output parameter must be NULL or a pointer to a buffer with >= PATH_MAX bytes
+ realpath(".", buf);
+
+ // This is fine.
+ realpath(".", NULL);
+
+ // FIXME: But we should warn on this.
+ realpath(NULL, buf);
+}