summaryrefslogtreecommitdiff
path: root/Kernel/CommandLine.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-08-21 15:06:12 -0600
committerAndreas Kling <kling@serenityos.org>2020-08-22 10:46:24 +0200
commit41c005cb140c8a9ae94e6b68456d8d6f1d925a8f (patch)
treec86f3b02ca2e7cdf3ec4caf68e08b45768f56c27 /Kernel/CommandLine.cpp
parent5a98e329d157a2db8379e0c97c6bdc1328027843 (diff)
downloadserenity-41c005cb140c8a9ae94e6b68456d8d6f1d925a8f.zip
Kernel: Copy command line to a safe place
This avoids kmalloc overwriting it because it may be within the kmalloc or eternal pool.
Diffstat (limited to 'Kernel/CommandLine.cpp')
-rw-r--r--Kernel/CommandLine.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp
index 3155dd6bdc..94109ea450 100644
--- a/Kernel/CommandLine.cpp
+++ b/Kernel/CommandLine.cpp
@@ -25,21 +25,34 @@
*/
#include <Kernel/CommandLine.h>
+#include <Kernel/StdLib.h>
namespace Kernel {
+static char s_cmd_line[1024];
static CommandLine* s_the;
+void CommandLine::early_initialize(const char* cmd_line)
+{
+ if (!cmd_line)
+ return;
+ size_t length = strlen(cmd_line);
+ if (length >= sizeof(s_cmd_line))
+ length = sizeof(s_cmd_line) -1;
+ memcpy(s_cmd_line, cmd_line, length);
+ s_cmd_line[length] = '\0';
+}
+
const CommandLine& kernel_command_line()
{
ASSERT(s_the);
return *s_the;
}
-void CommandLine::initialize(const String& string)
+void CommandLine::initialize()
{
ASSERT(!s_the);
- s_the = new CommandLine(string);
+ s_the = new CommandLine(s_cmd_line);
}
CommandLine::CommandLine(const String& string)