diff options
| author | Andreas Gampe <agampe@google.com> | 2014-08-19 16:57:38 -0700 |
|---|---|---|
| committer | Andreas Gampe <agampe@google.com> | 2014-08-25 10:25:00 -0700 |
| commit | 5f4f4aa2ada1360731aede29a11b9a708afd0e68 (patch) | |
| tree | d886a2829fcec3ef47676ea649bed30016c8f734 /JniInvocation.cpp | |
| parent | b14825c7c75420049e03849994265be651cc4a4e (diff) | |
| download | platform_libnativehelper-5f4f4aa2ada1360731aede29a11b9a708afd0e68.tar.gz platform_libnativehelper-5f4f4aa2ada1360731aede29a11b9a708afd0e68.tar.bz2 platform_libnativehelper-5f4f4aa2ada1360731aede29a11b9a708afd0e68.zip | |
NativeHelper: Do not allow arbitrary library strings in user builds
On device, only allow "libart.so" in non-debuggable (user) builds.
Bug: 16404669
(cherry picked from commit 5019faa3a6bdde33785ece0537e8b865ea7cf938)
Change-Id: Ie163c04ce40c82698dcc98ced651dafef094d8b5
Diffstat (limited to 'JniInvocation.cpp')
| -rw-r--r-- | JniInvocation.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/JniInvocation.cpp b/JniInvocation.cpp index 1764693..f4dd24e 100644 --- a/JniInvocation.cpp +++ b/JniInvocation.cpp @@ -50,13 +50,31 @@ JniInvocation::~JniInvocation() { #ifdef HAVE_ANDROID_OS static const char* kLibrarySystemProperty = "persist.sys.dalvik.vm.lib.2"; +static const char* kDebuggableSystemProperty = "ro.debuggable"; +static const char* kDebuggableFallback = "0"; // Not debuggable. #endif static const char* kLibraryFallback = "libart.so"; -bool JniInvocation::Init(const char* library) { +const char* JniInvocation::GetLibrary(const char* library) { #ifdef HAVE_ANDROID_OS char default_library[PROPERTY_VALUE_MAX]; - property_get(kLibrarySystemProperty, default_library, kLibraryFallback); + + char debuggable[PROPERTY_VALUE_MAX]; + property_get(kDebuggableSystemProperty, debuggable, kDebuggableFallback); + + if (strcmp(debuggable, "1") != 0) { + // Not a debuggable build. + // Do not allow arbitrary library. Ignore the library parameter. This + // will also ignore the default library, but initialize to empty string + // for cleanliness. + library = kLibraryFallback; + default_library[0] = 0; + } else { + // Debuggable build. + // Accept the library parameter. For the case it is NULL, load the default + // library from the system property. + property_get(kLibrarySystemProperty, default_library, kLibraryFallback); + } #else const char* default_library = kLibraryFallback; #endif @@ -64,6 +82,12 @@ bool JniInvocation::Init(const char* library) { library = default_library; } + return library; +} + +bool JniInvocation::Init(const char* library) { + library = GetLibrary(library); + handle_ = dlopen(library, RTLD_NOW); if (handle_ == NULL) { if (strcmp(library, kLibraryFallback) == 0) { |
