diff options
author | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2011-12-21 17:51:40 +0000 |
---|---|---|
committer | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2011-12-21 17:51:40 +0000 |
commit | ae5193c24ee046c5b8197ce76838a2b2c0e05e01 (patch) | |
tree | f8c7a7f3ac4b8c10bfb988b176d5b3fa70af0c17 /src/client/linux/crash_generation | |
parent | Refactor code in preparation of merging with the fork in Chromium OS. (diff) | |
download | breakpad-ae5193c24ee046c5b8197ce76838a2b2c0e05e01.tar.xz |
Replace readlink calls with a safer version that guarantees NULL-termination.
This patch is part of a bigger patch that helps merging the breakpad code
with the modified version in Chromium OS.
Specifically, this patch makes the following changes:
1. Add a SafeReadLink function that wraps sys_readlink() to resolve a
symbolic link but guarantees the result is NULL-terminated on success.
2. Refactor other source code to use SafeReadLink instead of readlink()
or sys_readlink().
BUG=455
TEST=Tested the following:
1. Build on 32-bit and 64-bit Linux with gcc 4.4.3 and gcc 4.6.
2. Build on Mac OS X 10.6.8 with gcc 4.2 and clang 3.0 (with latest gmock).
3. All unit tests pass.
4. Run minidump-2-core to covnert a minidump file to a core file.
Review URL: http://breakpad.appspot.com/334001
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@896 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/linux/crash_generation')
-rw-r--r-- | src/client/linux/crash_generation/crash_generation_server.cc | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/client/linux/crash_generation/crash_generation_server.cc b/src/client/linux/crash_generation/crash_generation_server.cc index 2f7edb69..76c9d9cd 100644 --- a/src/client/linux/crash_generation/crash_generation_server.cc +++ b/src/client/linux/crash_generation/crash_generation_server.cc @@ -47,6 +47,7 @@ #include "client/linux/minidump_writer/minidump_writer.h" #include "common/linux/eintr_wrapper.h" #include "common/linux/guid_creator.h" +#include "common/linux/safe_readlink.h" static const char kCommandQuit = 'x'; @@ -79,12 +80,10 @@ GetInodeForProcPath(ino_t* inode_out, const char* path) assert(inode_out); assert(path); - char buf[256]; - const ssize_t n = readlink(path, buf, sizeof(buf) - 1); - if (n == -1) { + char buf[PATH_MAX]; + if (!SafeReadLink(path, buf)) { return false; } - buf[n] = 0; if (0 != memcmp(kSocketLinkPrefix, buf, sizeof(kSocketLinkPrefix) - 1)) { return false; @@ -130,7 +129,7 @@ FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode) for (std::vector<pid_t>::const_iterator i = pids.begin(); i != pids.end(); ++i) { const pid_t current_pid = *i; - char buf[256]; + char buf[PATH_MAX]; snprintf(buf, sizeof(buf), "/proc/%d/fd", current_pid); DIR* fd = opendir(buf); if (!fd) |