summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-08-24 19:35:27 -0600
committerAndreas Kling <kling@serenityos.org>2020-08-25 09:48:48 +0200
commit81780e607da83c60e060288ccdbfb939540d84d3 (patch)
tree0b9f7d3390ea0c29a7e8673e7d6b03bf2dc1b05b /Kernel
parentd89582880ed81c38df67687eadfc0764b6ce5ddd (diff)
downloadserenity-81780e607da83c60e060288ccdbfb939540d84d3.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')
-rw-r--r--Kernel/CommandLine.cpp17
-rw-r--r--Kernel/CommandLine.h3
-rw-r--r--Kernel/init.cpp6
3 files changed, 22 insertions, 4 deletions
diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp
index 7f40aa18e9..685dba5aa8 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)
diff --git a/Kernel/CommandLine.h b/Kernel/CommandLine.h
index ec50cd4e9f..0d68f024bc 100644
--- a/Kernel/CommandLine.h
+++ b/Kernel/CommandLine.h
@@ -36,7 +36,8 @@ class CommandLine {
AK_MAKE_ETERNAL;
public:
- static void initialize(const String&);
+ static void early_initialize(const char* cmd_line);
+ static void initialize();
const String& string() const { return m_string; }
Optional<String> lookup(const String& key) const;
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index 200d852c8a..d38b91da18 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -113,6 +113,10 @@ extern "C" [[noreturn]] void init()
{
setup_serial_debug();
+ // We need to copy the command line before kmalloc is initialized,
+ // as it may overwrite parts of multiboot!
+ CommandLine::early_initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)));
+
s_bsp_processor.early_initialize(0);
// Invoke the constructors needed for the kernel heap
@@ -123,7 +127,7 @@ extern "C" [[noreturn]] void init()
s_bsp_processor.initialize(0);
- CommandLine::initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)));
+ CommandLine::initialize();
MemoryManager::initialize(0);
// Invoke all static global constructors in the kernel.