| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/plugins/plugin_lib.h" | 5 #include "webkit/glue/plugins/plugin_lib.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #if defined(OS_OPENBSD) | 8 #if defined(OS_OPENBSD) |
| 9 #include <sys/exec_elf.h> | 9 #include <sys/exec_elf.h> |
| 10 #else | 10 #else |
| 11 #include <elf.h> | 11 #include <elf.h> |
| 12 #include <fcntl.h> |
| 12 #endif | 13 #endif |
| 14 #include <sys/stat.h> |
| 15 #include <sys/types.h> |
| 16 #include <unistd.h> |
| 13 | 17 |
| 18 #include "base/eintr_wrapper.h" |
| 19 #include "base/file_util.h" |
| 14 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 15 #include "base/sys_string_conversions.h" | 21 #include "base/sys_string_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 17 #include "webkit/glue/plugins/plugin_list.h" | 23 #include "webkit/glue/plugins/plugin_list.h" |
| 18 | 24 |
| 19 // These headers must be included in this order to make the declaration gods | 25 // These headers must be included in this order to make the declaration gods |
| 20 // happy. | 26 // happy. |
| 21 #include "base/third_party/nspr/prcpucfg_linux.h" | 27 #include "base/third_party/nspr/prcpucfg_linux.h" |
| 22 | 28 |
| 23 namespace { | 29 namespace { |
| 24 | 30 |
| 25 // Copied from nsplugindefs.h instead of including the file since it has a bunch | 31 // Copied from nsplugindefs.h instead of including the file since it has a bunch |
| 26 // of dependencies. | 32 // of dependencies. |
| 27 enum nsPluginVariable { | 33 enum nsPluginVariable { |
| 28 nsPluginVariable_NameString = 1, | 34 nsPluginVariable_NameString = 1, |
| 29 nsPluginVariable_DescriptionString = 2 | 35 nsPluginVariable_DescriptionString = 2 |
| 30 }; | 36 }; |
| 31 | 37 |
| 32 // Read the ELF header and return true if it is usable on | 38 // Read the ELF header and return true if it is usable on |
| 33 // the current architecture (e.g. 32-bit ELF on 32-bit build). | 39 // the current architecture (e.g. 32-bit ELF on 32-bit build). |
| 34 // Returns false on other errors as well. | 40 // Returns false on other errors as well. |
| 35 bool ELFMatchesCurrentArchitecture(const FilePath& filename) { | 41 bool ELFMatchesCurrentArchitecture(const FilePath& filename) { |
| 36 FILE* file = fopen(filename.value().c_str(), "rb"); | 42 // First make sure we can open the file and it is in fact, a regular file. |
| 37 if (!file) | 43 struct stat stat_buf; |
| 44 // Open with O_NONBLOCK so we don't block on pipes. |
| 45 int fd = open(filename.value().c_str(), O_RDONLY|O_NONBLOCK); |
| 46 if (fd < 0) |
| 47 return false; |
| 48 bool ret = (fstat(fd, &stat_buf) >= 0 && S_ISREG(stat_buf.st_mode)); |
| 49 if (HANDLE_EINTR(close(fd)) < 0) |
| 50 return false; |
| 51 if (!ret) |
| 38 return false; | 52 return false; |
| 39 | 53 |
| 40 char buffer[5]; | 54 const size_t kELFBufferSize = 5; |
| 41 if (fread(buffer, 5, 1, file) != 1) { | 55 char buffer[kELFBufferSize]; |
| 42 fclose(file); | 56 if (!file_util::ReadFile(filename, buffer, kELFBufferSize)) |
| 43 return false; | 57 return false; |
| 44 } | |
| 45 fclose(file); | |
| 46 | 58 |
| 47 if (buffer[0] != ELFMAG0 || | 59 if (buffer[0] != ELFMAG0 || |
| 48 buffer[1] != ELFMAG1 || | 60 buffer[1] != ELFMAG1 || |
| 49 buffer[2] != ELFMAG2 || | 61 buffer[2] != ELFMAG2 || |
| 50 buffer[3] != ELFMAG3) { | 62 buffer[3] != ELFMAG3) { |
| 51 // Not an ELF file, perhaps? | 63 // Not an ELF file, perhaps? |
| 52 return false; | 64 return false; |
| 53 } | 65 } |
| 54 | 66 |
| 55 int elf_class = buffer[EI_CLASS]; | 67 int elf_class = buffer[EI_CLASS]; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 mime_type.description = UTF8ToWide(description.substr(ofs)); | 221 mime_type.description = UTF8ToWide(description.substr(ofs)); |
| 210 } | 222 } |
| 211 mime_types->push_back(mime_type); | 223 mime_types->push_back(mime_type); |
| 212 if (end == std::string::npos) | 224 if (end == std::string::npos) |
| 213 break; | 225 break; |
| 214 ofs = end + 1; | 226 ofs = end + 1; |
| 215 } | 227 } |
| 216 } | 228 } |
| 217 | 229 |
| 218 } // namespace NPAPI | 230 } // namespace NPAPI |
| OLD | NEW |