diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 01:10:49 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 01:10:49 +0000 |
commit | 6ee15630603b46b24c02dcf4d4cf8b8412af52aa (patch) | |
tree | 623a5573fcc2bade1fb69c8a59408ad6f1fed603 | |
parent | 22f50091721da306901b408c2ccacc6407252863 (diff) | |
download | chromium_src-6ee15630603b46b24c02dcf4d4cf8b8412af52aa.zip chromium_src-6ee15630603b46b24c02dcf4d4cf8b8412af52aa.tar.gz chromium_src-6ee15630603b46b24c02dcf4d4cf8b8412af52aa.tar.bz2 |
linux: test plugin for appropriate architecture before loading
We'd like to print any dlopen() errors, but opening a 32-bit plugin
on a 64-bit system is an avoidable one. This also filters out any
Firefox-specific .xpis that may happen to be in the plugin directory.
TEST=about:plugins shows same plugins as before, but with less console spew
Review URL: http://codereview.chromium.org/174487
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24397 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/plugins/plugin_lib_linux.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/webkit/glue/plugins/plugin_lib_linux.cc b/webkit/glue/plugins/plugin_lib_linux.cc index 7da3e44..559495a 100644 --- a/webkit/glue/plugins/plugin_lib_linux.cc +++ b/webkit/glue/plugins/plugin_lib_linux.cc @@ -5,6 +5,7 @@ #include "webkit/glue/plugins/plugin_lib.h" #include <dlfcn.h> +#include <elf.h> #include "base/string_util.h" #include "base/sys_string_conversions.h" @@ -15,6 +16,45 @@ #include "base/third_party/nspr/prcpucfg_linux.h" #include "third_party/mozilla/include/nsplugindefs.h" +namespace { + +// Read the ELF header and return true if it is usable on +// the current architecture (e.g. 32-bit ELF on 32-bit build). +// Returns false on other errors as well. +bool ELFMatchesCurrentArchitecture(const FilePath& filename) { + FILE* file = fopen(filename.value().c_str(), "rb"); + if (!file) + return false; + + char buffer[5]; + if (fread(buffer, 5, 1, file) != 1) { + fclose(file); + return false; + } + fclose(file); + + if (buffer[0] != ELFMAG0 || + buffer[1] != ELFMAG1 || + buffer[2] != ELFMAG2 || + buffer[3] != ELFMAG3) { + // Not an ELF file, perhaps? + return false; + } + + int elf_class = buffer[EI_CLASS]; +#if defined(ARCH_CPU_32_BITS) + if (elf_class == ELFCLASS32) + return true; +#elif defined(ARCH_CPU_64_BITS) + if (elf_class == ELFCLASS64) + return true; +#endif + + return false; +} + + +} // anonymous namespace namespace NPAPI { bool PluginLib::ReadWebPluginInfo(const FilePath& filename, @@ -22,6 +62,10 @@ bool PluginLib::ReadWebPluginInfo(const FilePath& filename, // The file to reference is: // http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginsDirUnix.cpp + // Skip files that aren't appropriate for our architecture. + if (!ELFMatchesCurrentArchitecture(filename)) + return false; + void* dl = base::LoadNativeLibrary(filename); if (!dl) return false; |