From: Oliver Kurth Date: Tue, 30 Apr 2019 20:24:25 +0000 (-0700) Subject: Fix Coverity reported issues in i18n.c code - VMTools & VGAuth X-Git-Tag: stable-11.0.0~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=642d7a61db13969f9fb654ad1cc0d879bf680612;p=thirdparty%2Fopen-vm-tools.git 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. --- diff --git a/open-vm-tools/libvmtools/i18n.c b/open-vm-tools/libvmtools/i18n.c index 40d9a68df..d8cef330f 100644 --- a/open-vm-tools/libvmtools/i18n.c +++ b/open-vm-tools/libvmtools/i18n.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2010-2018 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/open-vm-tools/vgauth/common/i18n.c b/open-vm-tools/vgauth/common/i18n.c index be9dc7ac4..896b6d4fd 100644 --- a/open-vm-tools/vgauth/common/i18n.c +++ b/open-vm-tools/vgauth/common/i18n.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2018 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; } }