diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-11-20 15:20:23 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-21 11:49:06 +0000 |
commit | 06f140a025dd24d268ea798474813ad4daa49b37 (patch) | |
tree | afb4dcec44534c7111aacbc3c1c6315e08ec8dad | |
parent | c80dcc46719583d8cf3ec2d57d349e71cd998f04 (diff) | |
download | serenity-06f140a025dd24d268ea798474813ad4daa49b37.zip |
LibGUI: Avoid access to Clipboard server, clipboard text is never empty
The clipboard cannot reasonably contain the empty string. The clipboard
can be empty (i.e. cleared), sure, but that this check was about whether
the clipboard contained the empty string.
This cannot easily happen for two reasons:
- TextEditor GUI elements disable their copy actions when the selection
is empty.
- Clipboard::set_data, through which all text-copying operates,
implicitly forbids empty strings, because Process::sys$anon_create
forbids empty anonymous files.
- Even if it were sent (e.g. by creating a non-empty anonymous file and
sending it manually to the Clipboard server), it would not be
received, because decode(Decoder&, Core::AnonymousBuffer&) goes
through mmap() with a size of 0, which also is forbidden by the
Kernel.
In other words, if the clipboard is never the empty text, therefore
checking this condition is pointless, and we can save a roundtrip to the
Clipboard server.
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index c69bb69f8a..32c62ba895 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -83,7 +83,7 @@ void TextEditor::create_actions() m_cut_action->set_enabled(false); m_copy_action->set_enabled(false); m_paste_action = CommonActions::make_paste_action([&](auto&) { paste(); }, this); - m_paste_action->set_enabled(is_editable() && Clipboard::the().mime_type().starts_with("text/") && !Clipboard::the().data().is_empty()); + m_paste_action->set_enabled(is_editable() && Clipboard::the().mime_type().starts_with("text/")); if (is_multi_line()) { m_go_to_line_action = Action::create( "Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) { @@ -1882,7 +1882,7 @@ void TextEditor::cursor_did_change() void TextEditor::clipboard_content_did_change(String const& mime_type) { - m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty()); + m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/")); } void TextEditor::set_document(TextDocument& document) |