Blame SOURCES/ovt-copyPasteCompatX11.c-code-generating-unnecessary-Cov.patch

604589
From d56ab64ed0b7a863cc2b0bf1dc78bbf3d3953226 Mon Sep 17 00:00:00 2001
604589
From: Cathy Avery <cavery@redhat.com>
604589
Date: Thu, 25 Jul 2019 12:32:37 +0200
604589
Subject: [PATCH 14/16] copyPasteCompatX11.c code generating unnecessary
604589
 Coverity warning
604589
604589
RH-Author: Cathy Avery <cavery@redhat.com>
604589
Message-id: <20190725123239.18274-15-cavery@redhat.com>
604589
Patchwork-id: 89721
604589
O-Subject: [RHEL8.1 open-vm-tools PATCH 14/16] copyPasteCompatX11.c code generating unnecessary Coverity warning
604589
Bugzilla: 1602648
604589
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
604589
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
604589
604589
commit 9c30be3448c743e51718480543142bf833ea553a
604589
Author: Oliver Kurth <okurth@vmware.com>
604589
Date:   Mon Jun 17 11:41:38 2019 -0700
604589
604589
    copyPasteCompatX11.c code generating unnecessary Coverity warning
604589
604589
    This patch aims to fix an issue found by Coverity Scan.
604589
604589
    This issue is a False Positive, the outBuf is only freed in specific
604589
    scenario, so there is no 'BAD FREE'.  But it's better to reconstruct the
604589
    related code to clear the SCA error.
604589
604589
Signed-off-by: Cathy Avery <cavery@redhat.com>
604589
604589
Conflicts: Minor copyright
604589
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
604589
---
604589
 .../services/plugins/dndcp/copyPasteCompatX11.c    | 43 +++++++++-------------
604589
 1 file changed, 17 insertions(+), 26 deletions(-)
604589
604589
diff --git a/services/plugins/dndcp/copyPasteCompatX11.c b/services/plugins/dndcp/copyPasteCompatX11.c
604589
index d5a0fdf..3b2f2bc 100644
604589
--- a/services/plugins/dndcp/copyPasteCompatX11.c
604589
+++ b/services/plugins/dndcp/copyPasteCompatX11.c
604589
@@ -1,5 +1,5 @@
604589
 /*********************************************************
604589
- * Copyright (C) 2005-2016 VMware, Inc. All rights reserved.
604589
+ * Copyright (C) 2005-2019 VMware, Inc. All rights reserved.
604589
  *
604589
  * This program is free software; you can redistribute it and/or modify it
604589
  * under the terms of the GNU Lesser General Public License as published
604589
@@ -579,50 +579,41 @@ CopyPasteSelectionGetCB(GtkWidget        *widget,         // IN: unused
604589
       return;
604589
    }
604589
 
604589
-   /* If it is text copy paste, return gHostClipboardBuf. */
604589
+   GdkAtom target;
604589
 #ifndef GTK3
604589
-   if (GDK_SELECTION_TYPE_STRING == selection_data->target ||
604589
-       GDK_SELECTION_TYPE_UTF8_STRING == selection_data->target) {
604589
+   target = selection_data->target;
604589
 #else
604589
-   if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data) ||
604589
-       GDK_SELECTION_TYPE_UTF8_STRING == gtk_selection_data_get_target(selection_data)) {
604589
+   target = gtk_selection_data_get_target(selection_data);
604589
 #endif
604589
+
604589
+   /* If it is text copy paste, return gHostClipboardBuf. */
604589
+   if (GDK_SELECTION_TYPE_STRING == target ||
604589
+       GDK_SELECTION_TYPE_UTF8_STRING == target) {
604589
       char *outBuf = gHostClipboardBuf;
604589
+      char *outStringBuf = NULL;
604589
       size_t len = strlen(gHostClipboardBuf);
604589
 
604589
       /*
604589
        * If target is GDK_SELECTION_TYPE_STRING, assume encoding is local code
604589
        * set. Convert from utf8 to local one.
604589
        */
604589
-#ifndef GTK3
604589
-      if (GDK_SELECTION_TYPE_STRING == selection_data->target &&
604589
-#else
604589
-      if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data) &&
604589
-#endif
604589
+      if (GDK_SELECTION_TYPE_STRING == target &&
604589
           !CodeSet_Utf8ToCurrent(gHostClipboardBuf,
604589
                                  strlen(gHostClipboardBuf),
604589
-                                 &outBuf,
604589
+                                 &outStringBuf,
604589
                                  &len)) {
604589
          g_debug("CopyPasteSelectionGetCB: can not convert to current codeset\n");
604589
          return;
604589
       }
604589
 
604589
-#ifndef GTK3
604589
-      gtk_selection_data_set(selection_data, selection_data->target, 8,
604589
-#else
604589
-      gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8,
604589
-#endif
604589
-                             outBuf, len);
604589
-      g_debug("CopyPasteSelectionGetCB: Set text [%s]\n", outBuf);
604589
-
604589
-#ifndef GTK3
604589
-      if (GDK_SELECTION_TYPE_STRING == selection_data->target) {
604589
-#else
604589
-      if (GDK_SELECTION_TYPE_STRING == gtk_selection_data_get_target(selection_data)) {
604589
-#endif
604589
-         free(outBuf);
604589
+      if (outStringBuf != NULL) {
604589
+         outBuf = outStringBuf;
604589
       }
604589
 
604589
+      gtk_selection_data_set(selection_data, target, 8, outBuf, len);
604589
+      g_debug("CopyPasteSelectionGetCB: Set text [%s]\n", outBuf);
604589
+
604589
+      free(outStringBuf);
604589
       return;
604589
    }
604589
 }
604589
-- 
604589
1.8.3.1
604589