Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: kernel_collector.cc

Issue 4603001: crash-reporter: Avoid writing through symlinks. (Closed) Base URL: http://git.chromium.org/git/crash-reporter.git@master
Patch Set: Respond to review Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « crash_collector_test.cc ('k') | user_collector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 "crash-reporter/kernel_collector.h" 5 #include "crash-reporter/kernel_collector.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "crash-reporter/system_logging.h" 10 #include "crash-reporter/system_logging.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 return true; 270 return true;
271 } 271 }
272 272
273 std::string dump_basename = 273 std::string dump_basename =
274 FormatDumpBasename(kKernelExecName, 274 FormatDumpBasename(kKernelExecName,
275 time(NULL), 275 time(NULL),
276 kKernelPid); 276 kKernelPid);
277 FilePath kernel_crash_path = root_crash_directory.Append( 277 FilePath kernel_crash_path = root_crash_directory.Append(
278 StringPrintf("%s.kcrash", dump_basename.c_str())); 278 StringPrintf("%s.kcrash", dump_basename.c_str()));
279 279
280 if (file_util::WriteFile(kernel_crash_path, 280 // We must use WriteNewFile instead of file_util::WriteFile as we
281 kernel_dump.data(), 281 // do not want to write with root access to a symlink that an attacker
282 kernel_dump.length()) != 282 // might have created.
283 if (WriteNewFile(kernel_crash_path,
284 kernel_dump.data(),
285 kernel_dump.length()) !=
283 static_cast<int>(kernel_dump.length())) { 286 static_cast<int>(kernel_dump.length())) {
284 logger_->LogInfo("Failed to write kernel dump to %s", 287 logger_->LogInfo("Failed to write kernel dump to %s",
285 kernel_crash_path.value().c_str()); 288 kernel_crash_path.value().c_str());
286 return true; 289 return true;
287 } 290 }
288 291
289 AddCrashMetaData(kKernelSignatureKey, signature); 292 AddCrashMetaData(kKernelSignatureKey, signature);
290 WriteCrashMetaData( 293 WriteCrashMetaData(
291 root_crash_directory.Append( 294 root_crash_directory.Append(
292 StringPrintf("%s.meta", dump_basename.c_str())), 295 StringPrintf("%s.meta", dump_basename.c_str())),
293 kKernelExecName, 296 kKernelExecName,
294 kernel_crash_path.value()); 297 kernel_crash_path.value());
295 298
296 logger_->LogInfo("Stored kcrash to %s", 299 logger_->LogInfo("Stored kcrash to %s",
297 kernel_crash_path.value().c_str()); 300 kernel_crash_path.value().c_str());
298 } 301 }
299 if (!ClearPreservedDump()) { 302 if (!ClearPreservedDump()) {
300 return false; 303 return false;
301 } 304 }
302 305
303 return true; 306 return true;
304 } 307 }
OLDNEW
« no previous file with comments | « crash_collector_test.cc ('k') | user_collector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698