Merge "Fix ubsan failure in android::base::Split." am: aa9548dbb4
am: 09980cd1a8
Change-Id: I49116f209d65365cc1caf3a50c09c7cc4178ecff
diff --git a/base/Android.bp b/base/Android.bp
index 7f81915..df09784 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -37,6 +37,9 @@
cppflags: libbase_cppflags,
export_include_dirs: ["include"],
shared_libs: ["liblog"],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
target: {
android: {
srcs: [
@@ -97,6 +100,9 @@
"strings_test.cpp",
"test_main.cpp",
],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
target: {
android: {
srcs: [
diff --git a/base/strings.cpp b/base/strings.cpp
index 46fe939..bfdaf12 100644
--- a/base/strings.cpp
+++ b/base/strings.cpp
@@ -36,11 +36,12 @@
size_t base = 0;
size_t found;
- do {
+ while (true) {
found = s.find_first_of(delimiters, base);
result.push_back(s.substr(base, found - base));
+ if (found == s.npos) break;
base = found + 1;
- } while (found != s.npos);
+ }
return result;
}
diff --git a/base/strings_test.cpp b/base/strings_test.cpp
index 7a65a00..7ed5b2b 100644
--- a/base/strings_test.cpp
+++ b/base/strings_test.cpp
@@ -251,3 +251,7 @@
ASSERT_FALSE(android::base::EqualsIgnoreCase("foo", "bar"));
ASSERT_FALSE(android::base::EqualsIgnoreCase("foo", "fool"));
}
+
+TEST(strings, ubsan_28729303) {
+ android::base::Split("/dev/null", ":");
+}