]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix Coverity reported issues in i18n.c code - VMTools & VGAuth
authorOliver Kurth <okurth@vmware.com>
Tue, 30 Apr 2019 20:24:25 +0000 (13:24 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 30 Apr 2019 20:24:25 +0000 (13:24 -0700)
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.

open-vm-tools/libvmtools/i18n.c
open-vm-tools/vgauth/common/i18n.c

index 40d9a68dfd273093744c084f7f018e8e26cc85c6..d8cef330f500c548d313eefaf4ac89149e34932d 100644 (file)
@@ -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) {
index be9dc7ac43ec1208ade76e4344a4a971bc7f589a..896b6d4fdb3179c29f1259dfefa39c3b46b3a4d5 100644 (file)
@@ -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;
       }
    }