From bbfccc2561b125971d714baba5c4aa97e6fdd181 Mon Sep 17 00:00:00 2001 From: Cathy Avery Date: Thu, 25 Jul 2019 12:32:29 +0200 Subject: [PATCH 06/16] Fix Coverity reported issues in i18n.c code - VMTools & VGAuth RH-Author: Cathy Avery Message-id: <20190725123239.18274-7-cavery@redhat.com> Patchwork-id: 89713 O-Subject: [RHEL8.1 open-vm-tools PATCH 06/16] Fix Coverity reported issues in i18n.c code - VMTools & VGAuth Bugzilla: 1602648 RH-Acked-by: Vitaly Kuznetsov RH-Acked-by: Miroslav Rezanina commit 642d7a61db13969f9fb654ad1cc0d879bf680612 Author: Oliver Kurth Date: Tue Apr 30 13:24:25 2019 -0700 Fix Coverity reported issues in i18n.c code - VMTools & VGAuth bora-vmsoft/apps/vmtoolsbib/i18n.c: MsgLoadCatalog() - Coverity reported memory leak when an error is encountered parsing a line from a message catalog. - Second memory leak on error missed. bora-vmsoft/vgauth/common/i18n.c: MsgLoadCatalog() - Coverity reported some dead code. - Missed reporting memory leak when error is encountered parsing a line from a message catalog. Signed-off-by: Cathy Avery Conflicts: Minor copyright Signed-off-by: Miroslav Rezanina --- open-vm-tools/libvmtools/i18n.c | 10 ++++++---- open-vm-tools/vgauth/common/i18n.c | 19 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libvmtools/i18n.c b/libvmtools/i18n.c index e4803ab..7dc0092 100644 --- a/libvmtools/i18n.c +++ b/libvmtools/i18n.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2010-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2010-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 @@ -604,7 +604,7 @@ MsgLoadCatalog(const char *path) /* * If not a continuation line and we have a name, break out of the - * inner loop to update the dictionaty. + * inner loop to update the dictionary. */ if (!cont && name != NULL) { g_free(line); @@ -624,6 +624,8 @@ MsgLoadCatalog(const char *path) } if (error) { + free(name); + free(value); break; } @@ -634,6 +636,8 @@ MsgLoadCatalog(const char *path) !Unicode_IsBufferValid(value, strlen(value) + 1, STRING_ENCODING_UTF8)) { g_warning("Invalid UTF-8 string in message catalog (key = %s)\n", name); error = TRUE; + free(name); + free(value); break; } @@ -641,8 +645,6 @@ MsgLoadCatalog(const char *path) HashTable_ReplaceOrInsert(dict, name, g_strdup(value)); free(name); free(value); - name = NULL; - value = NULL; } if (eof) { diff --git a/vgauth/common/i18n.c b/vgauth/common/i18n.c index 85a435a..5580765 100644 --- a/vgauth/common/i18n.c +++ b/vgauth/common/i18n.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2011-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 @@ -571,7 +571,6 @@ MsgLoadCatalog(const char *path) g_free, g_free); for (;;) { - gboolean eof = FALSE; char *name = NULL; char *value = NULL; gchar *line; @@ -593,7 +592,7 @@ MsgLoadCatalog(const char *path) } if (line == NULL) { - eof = TRUE; + /* This signifies EOF. */ break; } @@ -619,6 +618,10 @@ MsgLoadCatalog(const char *path) g_free(line); if (error) { + /* + * If the local DictLL_UnmarshalLine() returns NULL, name and value + * will remain NULL pointers. No malloc'ed memory to free here. + */ break; } @@ -630,6 +633,8 @@ MsgLoadCatalog(const char *path) !g_utf8_validate(value, -1, NULL)) { g_warning("Invalid UTF-8 string in message catalog (key = %s)\n", name); error = TRUE; + g_free(name); + g_free(value); break; } @@ -637,14 +642,8 @@ MsgLoadCatalog(const char *path) val = g_strcompress(value); g_free(value); - // the hashtable takes ownership of the memory for 'name' and 'value' + // the hashtable takes ownership of the memory for 'name' and 'val' g_hash_table_insert(dict, name, val); - name = NULL; - value = NULL; - } - - if (eof) { - break; } } -- 1.8.3.1