diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-26 22:43:07 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-26 22:43:07 +0000 |
commit | fda5dffa8a730e506add93fc9dcf8c95c98a8b1d (patch) | |
tree | 7d216f2d56923c0f2860bf4d4bb9175a5ed1e642 /webkit | |
parent | c8b351dcf58bdd97c1854bae48bd4cdc88780cd5 (diff) | |
download | chromium_src-fda5dffa8a730e506add93fc9dcf8c95c98a8b1d.zip chromium_src-fda5dffa8a730e506add93fc9dcf8c95c98a8b1d.tar.gz chromium_src-fda5dffa8a730e506add93fc9dcf8c95c98a8b1d.tar.bz2 |
POSIX: Make sure files in plugin directories are regular files.
BUG=none
TEST=Visiting about:plugins with MOZ_PLUGIN_PATH=/tmp does not hang when there is a pipe in /tmp.
Review URL: http://codereview.chromium.org/1700014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45638 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/plugin_lib_posix.cc | 28 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list_posix.cc | 10 |
2 files changed, 25 insertions, 13 deletions
diff --git a/webkit/glue/plugins/plugin_lib_posix.cc b/webkit/glue/plugins/plugin_lib_posix.cc index 6541a66..00e85e4 100644 --- a/webkit/glue/plugins/plugin_lib_posix.cc +++ b/webkit/glue/plugins/plugin_lib_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,8 +9,14 @@ #include <sys/exec_elf.h> #else #include <elf.h> +#include <fcntl.h> #endif +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include "base/eintr_wrapper.h" +#include "base/file_util.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" @@ -33,16 +39,22 @@ enum nsPluginVariable { // 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) + // First make sure we can open the file and it is in fact, a regular file. + struct stat stat_buf; + // Open with O_NONBLOCK so we don't block on pipes. + int fd = open(filename.value().c_str(), O_RDONLY|O_NONBLOCK); + if (fd < 0) + return false; + bool ret = (fstat(fd, &stat_buf) >= 0 && S_ISREG(stat_buf.st_mode)); + if (HANDLE_EINTR(close(fd)) < 0) + return false; + if (!ret) return false; - char buffer[5]; - if (fread(buffer, 5, 1, file) != 1) { - fclose(file); + const size_t kELFBufferSize = 5; + char buffer[kELFBufferSize]; + if (!file_util::ReadFile(filename, buffer, kELFBufferSize)) return false; - } - fclose(file); if (buffer[0] != ELFMAG0 || buffer[1] != ELFMAG1 || diff --git a/webkit/glue/plugins/plugin_list_posix.cc b/webkit/glue/plugins/plugin_list_posix.cc index f46a84b..0daa4b5 100644 --- a/webkit/glue/plugins/plugin_list_posix.cc +++ b/webkit/glue/plugins/plugin_list_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -94,9 +94,9 @@ void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) { // 2) NS_USER_PLUGINS_DIR: ~/.mozilla/plugins. // This is a de-facto standard, so even though we're not Mozilla, let's // look in there too. - const char* home = getenv("HOME"); - if (home) - plugin_dirs->push_back(FilePath(home).Append(".mozilla/plugins")); + FilePath home = file_util::GetHomeDir(); + if (!home.empty()) + plugin_dirs->push_back(home.Append(".mozilla/plugins")); // 3) NS_SYSTEM_PLUGINS_DIR: // This varies across different browsers and versions, so check 'em all. @@ -213,4 +213,4 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, return true; } -} // namespace NPAPI +} // namespace NPAPI |