Browse Source

LibGUI: Fix OOB read in Clipboard::set_data()

AnotherTest 4 years ago
parent
commit
02f251bb4a
1 changed files with 2 additions and 4 deletions
  1. 2 4
      Libraries/LibGUI/Clipboard.cpp

+ 2 - 4
Libraries/LibGUI/Clipboard.cpp

@@ -98,15 +98,13 @@ Clipboard::DataAndType Clipboard::data_and_type() const
 
 
 void Clipboard::set_data(ReadonlyBytes data, const String& type, const HashMap<String, String>& metadata)
 void Clipboard::set_data(ReadonlyBytes data, const String& type, const HashMap<String, String>& metadata)
 {
 {
-    auto shared_buffer = SharedBuffer::create_with_size(data.size() + 1);
+    auto shared_buffer = SharedBuffer::create_with_size(data.size());
     if (!shared_buffer) {
     if (!shared_buffer) {
         dbgprintf("GUI::Clipboard::set_data() failed to create a shared buffer\n");
         dbgprintf("GUI::Clipboard::set_data() failed to create a shared buffer\n");
         return;
         return;
     }
     }
     if (!data.is_empty())
     if (!data.is_empty())
-        memcpy(shared_buffer->data(), data.data(), data.size() + 1);
-    else
-        ((u8*)shared_buffer->data())[0] = '\0';
+        memcpy(shared_buffer->data(), data.data(), data.size());
     shared_buffer->seal();
     shared_buffer->seal();
     shared_buffer->share_with(connection().server_pid());
     shared_buffer->share_with(connection().server_pid());