Blame SOURCES/ovt-Fix-a-memory-leak-in-the-unicode-library.patch

604589
From e8686de42164135f78a0212e1bd8ad5b24ee60a0 Mon Sep 17 00:00:00 2001
604589
From: Cathy Avery <cavery@redhat.com>
604589
Date: Thu, 25 Jul 2019 12:32:30 +0200
604589
Subject: [PATCH 07/16] Fix a memory leak in the unicode library.
604589
604589
RH-Author: Cathy Avery <cavery@redhat.com>
604589
Message-id: <20190725123239.18274-8-cavery@redhat.com>
604589
Patchwork-id: 89717
604589
O-Subject: [RHEL8.1 open-vm-tools PATCH 07/16] Fix a memory leak in the unicode library.
604589
Bugzilla: 1602648
604589
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
604589
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
604589
604589
commit 9e6e3afa5b5c3dc11c7aa79454ca4c8184c87bdf
604589
Author: Oliver Kurth <okurth@vmware.com>
604589
Date:   Tue Apr 30 13:24:25 2019 -0700
604589
604589
    Fix a memory leak in the unicode library.
604589
604589
    Ensure that allocated strings are freed before returning a failure.
604589
604589
    The ASSERTs have never been known to fire; a warning in a obj
604589
    build will help with debugging. The warning should "never" happen.
604589
604589
Signed-off-by: Cathy Avery <cavery@redhat.com>
604589
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
604589
---
604589
 open-vm-tools/lib/unicode/unicodeICU.c | 30 +++++++++++++++++-------------
604589
 1 file changed, 17 insertions(+), 13 deletions(-)
604589
604589
diff --git a/lib/unicode/unicodeICU.c b/lib/unicode/unicodeICU.c
604589
index b63932e..b9b2dbb 100644
604589
--- a/lib/unicode/unicodeICU.c
604589
+++ b/lib/unicode/unicodeICU.c
604589
@@ -1,5 +1,5 @@
604589
 /*********************************************************
604589
- * Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
604589
+ * Copyright (C) 2008-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
@@ -275,7 +275,7 @@ Unicode_ToLower(const char *str,    // IN
604589
     */
604589
 
604589
    // Most lower-case operations don't change the length of the string.
604589
-   utf8Dest = (char *)Util_SafeMalloc(destCapacity);
604589
+   utf8Dest = Util_SafeMalloc(destCapacity);
604589
 
604589
    caseMap = ucasemap_open(locale, 0, &status);
604589
    if (U_FAILURE(status)) {
604589
@@ -295,7 +295,7 @@ Unicode_ToLower(const char *str,    // IN
604589
 
604589
    // If we need a bigger buffer, then reallocate and retry.
604589
    destCapacity = destLen + 1;
604589
-   utf8Dest = (char *)Util_SafeRealloc(utf8Dest, destCapacity);
604589
+   utf8Dest = Util_SafeRealloc(utf8Dest, destCapacity);
604589
 
604589
    status = U_ZERO_ERROR;
604589
    destLen = ucasemap_utf8ToLower(caseMap,
604589
@@ -311,8 +311,9 @@ Unicode_ToLower(const char *str,    // IN
604589
    if (U_SUCCESS(status) && status != U_STRING_NOT_TERMINATED_WARNING) {
604589
       result = utf8Dest;
604589
    } else {
604589
-      ASSERT(U_SUCCESS(status));
604589
-      ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
604589
+      DEBUG_ONLY(Warning("%s: Invalid UTF-8 string detected.\n",
604589
+                         __FUNCTION__));
604589
+      free(utf8Dest);
604589
    }
604589
 
604589
    return result;
604589
@@ -356,7 +357,7 @@ Unicode_ToUpper(const char *str,    // IN
604589
    char *result = NULL;
604589
 
604589
    // Most upper-case operations don't change the length of the string.
604589
-   utf8Dest = (char *)Util_SafeMalloc(destCapacity);
604589
+   utf8Dest = Util_SafeMalloc(destCapacity);
604589
 
604589
    caseMap = ucasemap_open(locale, 0, &status);
604589
    if (U_FAILURE(status)) {
604589
@@ -376,7 +377,7 @@ Unicode_ToUpper(const char *str,    // IN
604589
 
604589
    // If we need a bigger buffer, then reallocate and retry.
604589
    destCapacity = destLen + 1;
604589
-   utf8Dest = (char *)Util_SafeRealloc(utf8Dest, destCapacity);
604589
+   utf8Dest = Util_SafeRealloc(utf8Dest, destCapacity);
604589
 
604589
    status = U_ZERO_ERROR;
604589
    destLen = ucasemap_utf8ToUpper(caseMap,
604589
@@ -392,13 +393,15 @@ Unicode_ToUpper(const char *str,    // IN
604589
    if (U_SUCCESS(status) && status != U_STRING_NOT_TERMINATED_WARNING) {
604589
       result = utf8Dest;
604589
    } else {
604589
-      ASSERT(U_SUCCESS(status));
604589
-      ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
604589
+      DEBUG_ONLY(Warning("%s: Invalid UTF-8 string detected.\n",
604589
+                         __FUNCTION__));
604589
+      free(utf8Dest);
604589
    }
604589
 
604589
    return result;
604589
 }
604589
 
604589
+
604589
 /*
604589
  * "ucasemap_utf8ToTitle" is not in version 3.6 of the ICU library,
604589
  * which appears to be the default on many systems...
604589
@@ -447,7 +450,7 @@ Unicode_ToTitle(const char *str,    // IN
604589
    char *result = NULL;
604589
 
604589
    // Most title-case operations don't change the length of the string.
604589
-   utf8Dest = (char *)Util_SafeMalloc(destCapacity);
604589
+   utf8Dest = Util_SafeMalloc(destCapacity);
604589
 
604589
    caseMap = ucasemap_open(locale, 0, &status);
604589
    if (U_FAILURE(status)) {
604589
@@ -467,7 +470,7 @@ Unicode_ToTitle(const char *str,    // IN
604589
 
604589
    // If we need a bigger buffer, then reallocate and retry.
604589
    destCapacity = destLen + 1;
604589
-   utf8Dest = (char *)Util_SafeRealloc(utf8Dest, destCapacity);
604589
+   utf8Dest = Util_SafeRealloc(utf8Dest, destCapacity);
604589
 
604589
    status = U_ZERO_ERROR;
604589
    destLen = ucasemap_utf8ToTitle(caseMap,
604589
@@ -483,8 +486,9 @@ Unicode_ToTitle(const char *str,    // IN
604589
    if (U_SUCCESS(status) && status != U_STRING_NOT_TERMINATED_WARNING) {
604589
       result = utf8Dest;
604589
    } else {
604589
-      ASSERT(U_SUCCESS(status));
604589
-      ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
604589
+      DEBUG_ONLY(Warning("%s: Invalid UTF-8 string detected.\n",
604589
+                         __FUNCTION__));
604589
+      free(utf8Dest);
604589
    }
604589
 
604589
    return result;
604589
-- 
604589
1.8.3.1
604589