Merge "Restore __system_property_find_nth version" into oc-dev
diff --git a/libc/Android.bp b/libc/Android.bp
index 7fc4682..cde2391 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1817,6 +1817,7 @@
 cc_defaults {
     name: "crt_defaults",
     defaults: ["linux_bionic_supported"],
+    vendor_available: true,
 
     no_default_compiler_flags: true,
 
@@ -1846,6 +1847,7 @@
 cc_defaults {
     name: "crt_so_defaults",
 
+    vendor_available: true,
     arch: {
         mips: {
             cflags: ["-fPIC"],
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index a4faf85..2a42390 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -54,6 +54,7 @@
 #include <sys/_system_properties.h>
 #include <sys/system_properties.h>
 
+#include "private/ErrnoRestorer.h"
 #include "private/bionic_futex.h"
 #include "private/bionic_lock.h"
 #include "private/bionic_macros.h"
@@ -1096,6 +1097,9 @@
 }
 
 int __system_properties_init() {
+  // This is called from __libc_init_common, and should leave errno at 0 (http://b/37248982).
+  ErrnoRestorer errno_restorer;
+
   if (initialized) {
     list_foreach(contexts, [](context_node* l) { l->reset_access(); });
     return 0;
diff --git a/linker/linker_globals.h b/linker/linker_globals.h
index e4e3d97..1ed479c 100644
--- a/linker/linker_globals.h
+++ b/linker/linker_globals.h
@@ -34,6 +34,8 @@
 
 #include <unordered_map>
 
+#include "private/libc_logging.h"
+
 #define DL_ERR(fmt, x...) \
     do { \
       __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \
diff --git a/linker/linker_namespaces.cpp b/linker/linker_namespaces.cpp
index 273ff9b..3c86f99 100644
--- a/linker/linker_namespaces.cpp
+++ b/linker/linker_namespaces.cpp
@@ -27,6 +27,7 @@
  */
 
 #include "linker_namespaces.h"
+#include "linker_globals.h"
 #include "linker_soinfo.h"
 #include "linker_utils.h"
 
@@ -58,6 +59,13 @@
 
 bool android_namespace_t::is_accessible(soinfo* s) {
   auto is_accessible_ftor = [this] (soinfo* si) {
+    // This is workaround for apps hacking into soinfo list.
+    // and inserting their own entries into it. (http://b/37191433)
+    if (!si->has_min_version(3)) {
+      DL_WARN("invalid soinfo version for \"%s\"", si->get_soname());
+      return false;
+    }
+
     if (si->get_primary_namespace() == this) {
       return true;
     }