Bug 1438132 - Don't return false-positive data from clipboard, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Thu, 01 Mar 2018 14:07:15 +0100
changeset 461620 de07fd9fc0834e2a9efc4fc2fa7548ff6da2ef84
parent 461619 41c2952d093fc085ad1af837cdec964ded609006
child 461621 4e230122cb232925ed056206d3bc696203a98c4f
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1438132
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1438132 - Don't return false-positive data from clipboard, r=jhorak MozReview-Commit-ID: 5I9DbpYJ8EL
widget/gtk/nsClipboardWayland.cpp
--- a/widget/gtk/nsClipboardWayland.cpp
+++ b/widget/gtk/nsClipboardWayland.cpp
@@ -385,16 +385,19 @@ nsRetrievalContextWayland::TransferFastT
     }
 }
 
 const char*
 nsRetrievalContextWayland::GetClipboardData(const char* aMimeType,
                                             int32_t aWhichClipboard,
                                             uint32_t* aContentLength)
 {
+    NS_ASSERTION(mClipboardData == nullptr && mClipboardDataLength == 0,
+                 "Looks like we're leaking clipboard data here!");
+
     /* If actual clipboard data is owned by us we don't need to go
      * through Wayland but we ask Gtk+ to directly call data
      * getter callback nsClipboard::SelectionGetEvent().
      * see gtk_selection_convert() at gtk+/gtkselection.c.
      */
     GdkAtom selection = GetSelectionAtom(aWhichClipboard);
     if (gdk_selection_owner_get(selection)) {
         mClipboardRequestNumber++;
@@ -451,16 +454,24 @@ nsRetrievalContextWayland::GetClipboardD
             NS_WARNING(
                 nsPrintfCString("Unexpected error when reading clipboard data: %s",
                                 error->message).get());
             g_error_free(error);
         }
 
         g_io_channel_unref(channel);
         close(pipe_fd[0]);
+
+        // We don't have valid clipboard data although
+        // g_io_channel_read_to_end() allocated mClipboardData for us.
+        // Release it now and return nullptr to indicate
+        // we don't have reqested data flavour.
+        if (mClipboardData && mClipboardDataLength == 0) {
+            ReleaseClipboardData(mClipboardData);
+        }
     }
 
     *aContentLength = mClipboardDataLength;
     return reinterpret_cast<const char*>(mClipboardData);
 }
 
 void nsRetrievalContextWayland::ReleaseClipboardData(const char* aClipboardData)
 {