Blob Blame History Raw
From d56ab64ed0b7a863cc2b0bf1dc78bbf3d3953226 Mon Sep 17 00:00:00 2001
From: Cathy Avery <cavery@redhat.com>
Date: Thu, 25 Jul 2019 12:32:37 +0200
Subject: [PATCH 14/16] copyPasteCompatX11.c code generating unnecessary
 Coverity warning

RH-Author: Cathy Avery <cavery@redhat.com>
Message-id: <20190725123239.18274-15-cavery@redhat.com>
Patchwork-id: 89721
O-Subject: [RHEL8.1 open-vm-tools PATCH 14/16] copyPasteCompatX11.c code generating unnecessary Coverity warning
Bugzilla: 1602648
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>

commit 9c30be3448c743e51718480543142bf833ea553a
Author: Oliver Kurth <okurth@vmware.com>
Date:   Mon Jun 17 11:41:38 2019 -0700

    copyPasteCompatX11.c code generating unnecessary Coverity warning

    This patch aims to fix an issue found by Coverity Scan.

    This issue is a False Positive, the outBuf is only freed in specific
    scenario, so there is no 'BAD FREE'.  But it's better to reconstruct the
    related code to clear the SCA error.

Signed-off-by: Cathy Avery <cavery@redhat.com>

Conflicts: Minor copyright
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 .../services/plugins/dndcp/copyPasteCompatX11.c    | 43 +++++++++-------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/services/plugins/dndcp/copyPasteCompatX11.c b/services/plugins/dndcp/copyPasteCompatX11.c
index d5a0fdf..3b2f2bc 100644
--- a/services/plugins/dndcp/copyPasteCompatX11.c
+++ b/services/plugins/dndcp/copyPasteCompatX11.c
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2005-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2005-2019 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -579,50 +579,41 @@ CopyPasteSelectionGetCB(GtkWidget        *widget,         // IN: unused
       return;
    }
 
-   /* If it is text copy paste, return gHostClipboardBuf. */
+   GdkAtom target;
 #ifndef GTK3
-   if (GDK_SELECTION_TYPE_STRING == selection_data->target ||
-       GDK_SELECTION_TYPE_UTF8_STRING == selection_data->target) {
+   target = selection_data->target;
 #else
-   if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data) ||
-       GDK_SELECTION_TYPE_UTF8_STRING == gtk_selection_data_get_target(selection_data)) {
+   target = gtk_selection_data_get_target(selection_data);
 #endif
+
+   /* If it is text copy paste, return gHostClipboardBuf. */
+   if (GDK_SELECTION_TYPE_STRING == target ||
+       GDK_SELECTION_TYPE_UTF8_STRING == target) {
       char *outBuf = gHostClipboardBuf;
+      char *outStringBuf = NULL;
       size_t len = strlen(gHostClipboardBuf);
 
       /*
        * If target is GDK_SELECTION_TYPE_STRING, assume encoding is local code
        * set. Convert from utf8 to local one.
        */
-#ifndef GTK3
-      if (GDK_SELECTION_TYPE_STRING == selection_data->target &&
-#else
-      if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data) &&
-#endif
+      if (GDK_SELECTION_TYPE_STRING == target &&
           !CodeSet_Utf8ToCurrent(gHostClipboardBuf,
                                  strlen(gHostClipboardBuf),
-                                 &outBuf,
+                                 &outStringBuf,
                                  &len)) {
          g_debug("CopyPasteSelectionGetCB: can not convert to current codeset\n");
          return;
       }
 
-#ifndef GTK3
-      gtk_selection_data_set(selection_data, selection_data->target, 8,
-#else
-      gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8,
-#endif
-                             outBuf, len);
-      g_debug("CopyPasteSelectionGetCB: Set text [%s]\n", outBuf);
-
-#ifndef GTK3
-      if (GDK_SELECTION_TYPE_STRING == selection_data->target) {
-#else
-      if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data)) {
-#endif
-         free(outBuf);
+      if (outStringBuf != NULL) {
+         outBuf = outStringBuf;
       }
 
+      gtk_selection_data_set(selection_data, target, 8, outBuf, len);
+      g_debug("CopyPasteSelectionGetCB: Set text [%s]\n", outBuf);
+
+      free(outStringBuf);
       return;
    }
 }
-- 
1.8.3.1