From: Oliver Kurth Date: Mon, 17 Jun 2019 18:41:38 +0000 (-0700) Subject: copyPasteCompatX11.c code generating unnecessary Coverity warning X-Git-Tag: stable-11.0.0~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c30be3448c743e51718480543142bf833ea553a;p=thirdparty%2Fopen-vm-tools.git 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. --- diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c b/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c index 20b2cc011..e8eca5176 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c +++ b/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2005-2018 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 @@ -581,50 +581,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; } }