add fortified implementations of send/sendto
Bug: None
Test: Bullhead builds+boots; CtsBionicTestCases passes.
Change-Id: I2f137a100f679f7f2145d84b2f29ddd3e96a36ae
diff --git a/tests/fortify_compilation_test.cpp b/tests/fortify_compilation_test.cpp
index ea8e598..51074b2 100644
--- a/tests/fortify_compilation_test.cpp
+++ b/tests/fortify_compilation_test.cpp
@@ -310,3 +310,22 @@
// CLANG: 'memset' is deprecated: will set 0 bytes; maybe the arguments got flipped? (Add __bionic_zero_size_is_okay as a fourth argument to silence this.)
memset(from, sizeof(from), 0);
}
+
+void test_sendto() {
+ char buf[4] = {0};
+ 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
+ sendto(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), sizeof(sockaddr_in));
+}
+
+void test_send() {
+ 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
+ send(0, buf, 6, 0);
+}
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index e1ff769..86b282c 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -623,6 +623,12 @@
ASSERT_FORTIFY(recv(0, buf, data_len, 0));
}
+TEST_F(DEATHTEST, send_fortified) {
+ size_t data_len = atoi("11"); // suppress compiler optimizations
+ char buf[10] = {0};
+ ASSERT_FORTIFY(send(0, buf, data_len, 0));
+}
+
TEST_F(DEATHTEST, FD_ISSET_fortified) {
#if defined(__BIONIC__) // glibc catches this at compile-time.
fd_set set;