Check for bad packets in getaddrinfo.c's getanswer. am: 9ea3f1c8a5 am: 62b2f0523e am: 91b8b9dd71 -s ours am: 2ad4e6e4f6 am: c58d806231 am: ffcf543b9c am: c08dc9cbb3 am: bc9f3827ab am: 39d3f63f99
am: 9f6aad92e1
Change-Id: I6e20fed16e234c25d5fcd575597eab5ae2288f6b
diff --git a/libc/malloc_debug/backtrace.cpp b/libc/malloc_debug/backtrace.cpp
index 18ce8b8..75a255c 100644
--- a/libc/malloc_debug/backtrace.cpp
+++ b/libc/malloc_debug/backtrace.cpp
@@ -142,6 +142,8 @@
if (dladdr(reinterpret_cast<void*>(frames[frame_num]), &info) != 0) {
offset = reinterpret_cast<uintptr_t>(info.dli_saddr);
symbol = info.dli_sname;
+ } else {
+ info.dli_fname = nullptr;
}
uintptr_t rel_pc = offset;
diff --git a/tests/sys_prctl_test.cpp b/tests/sys_prctl_test.cpp
index 5a563c1..b7c542b 100644
--- a/tests/sys_prctl_test.cpp
+++ b/tests/sys_prctl_test.cpp
@@ -14,11 +14,19 @@
* limitations under the License.
*/
-#include <gtest/gtest.h>
-
+#include <inttypes.h>
+#include <stdio.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <unistd.h>
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "android-base/file.h"
+#include "android-base/strings.h"
#include "private/bionic_prctl.h"
// http://b/20017123.
@@ -29,9 +37,28 @@
ASSERT_NE(MAP_FAILED, p);
ASSERT_EQ(0, mprotect(p, page_size, PROT_NONE));
ASSERT_NE(-1, prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p, page_size * 3, "anonymous map space"));
- volatile char* vp = reinterpret_cast<volatile char*>(p);
- // Below memory access causes SEGV if the memory map is screwed up.
- *(vp + page_size) = 0;
+ // Now read the maps and verify that there are no overlapped maps.
+ std::string file_data;
+ ASSERT_TRUE(android::base::ReadFileToString("/proc/self/maps", &file_data));
+
+ uintptr_t last_start = 0;
+ uintptr_t last_end = 0;
+ std::vector<std::string> lines = android::base::Split(file_data, "\n");
+ for (size_t i = 0; i < lines.size(); i++) {
+ if (lines[i].empty()) {
+ continue;
+ }
+ uintptr_t start;
+ uintptr_t end;
+ ASSERT_EQ(2, sscanf(lines[i].c_str(), "%" SCNxPTR "-%" SCNxPTR " ", &start, &end))
+ << "Failed to parse line: " << lines[i];
+ // This will never fail on the first line, so no need to do any special checking.
+ ASSERT_GE(start, last_end)
+ << "Overlapping map detected:\n" << lines[i -1] << '\n' << lines[i] << '\n';
+ last_start = start;
+ last_end = end;
+ }
+
ASSERT_EQ(0, munmap(p, page_size * 3));
#else
GTEST_LOG_(INFO) << "This test does nothing as it tests an Android specific kernel feature.";