Blame SOURCES/ovt-Fix-Coverity-reported-issues-in-i18n.c-code-VMTools-.patch

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