render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From 38a50c517836b12720b963c498e303d677ec434c Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <38a50c517836b12720b963c498e303d677ec434c@dist-git>
c1c534
From: Martin Kletzander <mkletzan@redhat.com>
c1c534
Date: Wed, 31 Jan 2018 16:32:23 +0100
c1c534
Subject: [PATCH] util: Fix leak in virStringTrimOptionalNewline
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
c1c534
c1c534
Do not access any data if strlen() == 0.
c1c534
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
(cherry picked from commit ea7b2a6d04f5c354b1cda941362ba8ac42e92278)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
---
c1c534
 src/util/virstring.c | 10 +++++++---
c1c534
 1 file changed, 7 insertions(+), 3 deletions(-)
c1c534
c1c534
diff --git a/src/util/virstring.c b/src/util/virstring.c
c1c534
index eac4774b53..b2ebce27ff 100644
c1c534
--- a/src/util/virstring.c
c1c534
+++ b/src/util/virstring.c
c1c534
@@ -1394,9 +1394,13 @@ virStringEncodeBase64(const uint8_t *buf, size_t buflen)
c1c534
  */
c1c534
 void virStringTrimOptionalNewline(char *str)
c1c534
 {
c1c534
-    char *tmp = str + strlen(str) - 1;
c1c534
-    if (*tmp == '\n')
c1c534
-        *tmp = '\0';
c1c534
+    size_t len = strlen(str);
c1c534
+
c1c534
+    if (!len)
c1c534
+        return;
c1c534
+
c1c534
+    if (str[len - 1] == '\n')
c1c534
+        str[len - 1] = '\0';
c1c534
 }
c1c534
 
c1c534
 
c1c534
-- 
c1c534
2.16.1
c1c534