mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
d7734bf232
When there's a trailing space in the cmdline from the boot loader, this results in an empty string being emitted from `String::split` after splitting apart the argument list. This empty string resulted in a zero-length Vector from the subsequent call to split the key=value pairs, which was unexpected. This ultimately caused a crash when we tried to access `[0]` of that zero-length vector. We now detect and handle an empty string coming from `String::split` correctly.
39 lines
648 B
C++
39 lines
648 B
C++
#include <Kernel/KParams.h>
|
|
|
|
static KParams* s_the;
|
|
|
|
KParams& KParams::the()
|
|
{
|
|
return *s_the;
|
|
}
|
|
|
|
KParams::KParams(const String& cmdline)
|
|
: m_cmdline(cmdline)
|
|
{
|
|
s_the = this;
|
|
|
|
for (auto str : m_cmdline.split(' ')) {
|
|
if (str == "") {
|
|
continue;
|
|
}
|
|
|
|
auto pair = str.split_limit('=', 2);
|
|
|
|
if (pair.size() == 1) {
|
|
m_params.set(pair[0], "");
|
|
} else {
|
|
m_params.set(pair[0], pair[1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
String KParams::get(const String& key) const
|
|
{
|
|
return m_params.get(key);
|
|
}
|
|
|
|
bool KParams::has(const String& key) const
|
|
{
|
|
return m_params.contains(key);
|
|
}
|