aboutsummaryrefslogtreecommitdiff
path: root/src/common/linux/file_id_unittest.cc
diff options
context:
space:
mode:
authorbenchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2011-12-21 17:51:40 +0000
committerbenchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2011-12-21 17:51:40 +0000
commitae5193c24ee046c5b8197ce76838a2b2c0e05e01 (patch)
treef8c7a7f3ac4b8c10bfb988b176d5b3fa70af0c17 /src/common/linux/file_id_unittest.cc
parentRefactor code in preparation of merging with the fork in Chromium OS. (diff)
downloadbreakpad-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/common/linux/file_id_unittest.cc')
-rw-r--r--src/common/linux/file_id_unittest.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/common/linux/file_id_unittest.cc b/src/common/linux/file_id_unittest.cc
index 977f97d2..94bc80e4 100644
--- a/src/common/linux/file_id_unittest.cc
+++ b/src/common/linux/file_id_unittest.cc
@@ -33,12 +33,14 @@
#include <stdlib.h>
#include "common/linux/file_id.h"
+#include "common/linux/safe_readlink.h"
#include "common/linux/synth_elf.h"
#include "common/test_assembler.h"
#include "common/tests/auto_tempdir.h"
#include "breakpad_googletest_includes.h"
using namespace google_breakpad;
+using google_breakpad::SafeReadLink;
using google_breakpad::synth_elf::BuildIDNote;
using google_breakpad::synth_elf::ELF;
using google_breakpad::test_assembler::kLittleEndian;
@@ -61,9 +63,7 @@ TEST(FileIDStripTest, StripSelf) {
// FileID::ElfFileIdentifier, then make a copy of this binary,
// strip it, and ensure that the result is the same.
char exe_name[PATH_MAX];
- ssize_t len = readlink("/proc/self/exe", exe_name, PATH_MAX - 1);
- ASSERT_NE(len, -1);
- exe_name[len] = '\0';
+ ASSERT_TRUE(SafeReadLink("/proc/self/exe", exe_name));
// copy our binary to a temp file, and strip it
AutoTempDir temp_dir;