mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-12 17:37:53 +03:00
Kernel: Prevent kprintf() from asserting in Console::the() (#718)
This triggered a stack overflow because ubsan can call kprintf() at any time, even before Console is initialized.
This commit is contained in:
parent
8216019b2e
commit
81c4dcadf1
Notes:
sideshowbarker
2024-07-19 11:27:10 +09:00
Author: https://github.com/sleepy-monax Commit: https://github.com/SerenityOS/serenity/commit/81c4dcadf14 Pull-request: https://github.com/SerenityOS/serenity/pull/718 Reviewed-by: https://github.com/awesomekling
@ -13,6 +13,11 @@ Console& Console::the()
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
bool Console::is_initialized()
|
||||
{
|
||||
return s_the != nullptr;
|
||||
}
|
||||
|
||||
Console::Console()
|
||||
: CharacterDevice(5, 1)
|
||||
{
|
||||
|
@ -14,6 +14,7 @@ class Console final : public CharacterDevice {
|
||||
AK_MAKE_ETERNAL
|
||||
public:
|
||||
static Console& the();
|
||||
static bool is_initialized();
|
||||
|
||||
Console();
|
||||
virtual ~Console() override;
|
||||
|
@ -70,7 +70,14 @@ static void console_putch(char*&, char ch)
|
||||
{
|
||||
if (serial_debug)
|
||||
serial_putch(ch);
|
||||
Console::the().put_char(ch);
|
||||
|
||||
// It would be bad to reach the assert in Console()::the() and do a stack overflow
|
||||
|
||||
if (Console::is_initialized()) {
|
||||
Console::the().put_char(ch);
|
||||
} else {
|
||||
IO::out8(0xe9, ch);
|
||||
}
|
||||
}
|
||||
|
||||
int kprintf(const char* fmt, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user