open-vm-tools/SOURCES/ovt-Fix-a-memory-leak-in-the-unicode-library.patch
2021-09-09 23:20:50 +00:00

141 lines
5.0 KiB
Diff

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