vfs: check userland buffers before reading them.
[haiku.git] / src / apps / debugger / user_interface / cli / commands / CliWriteCoreFileCommand.cpp
blob2c61a057089cb5d2470bcc89a9400dd2db1b43fe
1 /*
2 * Copyright 2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "CliWriteCoreFileCommand.h"
9 #include <Entry.h>
10 #include <FindDirectory.h>
11 #include <Path.h>
12 #include <String.h>
14 #include "CliContext.h"
15 #include "UiUtils.h"
16 #include "UserInterface.h"
19 CliWriteCoreFileCommand::CliWriteCoreFileCommand()
21 CliCommand("write core file",
22 "%s\n"
23 "Writes a core dump file for the current team.")
28 void
29 CliWriteCoreFileCommand::Execute(int argc, const char* const* argv, CliContext& context)
31 BPath path;
32 if (argc > 1) {
33 path.SetTo(argv[1]);
34 if (path.InitCheck() != B_OK) {
35 printf("Invalid core file path %s given.\n", argv[1]);
36 return;
38 } else {
39 char buffer[B_FILE_NAME_LENGTH];
40 UiUtils::CoreFileNameForTeam(context.GetTeam(), buffer,
41 sizeof(buffer));
42 find_directory(B_DESKTOP_DIRECTORY, &path);
43 path.Append(buffer);
46 entry_ref ref;
47 if (get_ref_for_path(path.Path(), &ref) == B_OK) {
48 printf("Writing core file to %s...\n", path.Path());
49 context.GetUserInterfaceListener()->WriteCoreFileRequested(&ref);