render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From c8e10c7f4644646194bbcb1514bbf110ec7374ad Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <c8e10c7f4644646194bbcb1514bbf110ec7374ad@dist-git>
Pablo Greco 40546a
From: John Ferlan <jferlan@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:11 +0200
Pablo Greco 40546a
Subject: [PATCH] tests: Resolve possible overrun
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
Coverity noted that each of the fmemopen called used the strlen value
Pablo Greco 40546a
in order to allocate space, but that neglected space for terminating
Pablo Greco 40546a
null string. So just add 1 to the strlen.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: John Ferlan <jferlan@redhat.com>
Pablo Greco 40546a
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 7eb56dcd9ef4c21f8f4bc5e639dc4dd01e6d572a)
Pablo Greco 40546a
Pablo Greco 40546a
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Message-Id: <a0d52bead1b7e31bfa1c1938c7ae19fe0a7605d4.1561993099.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 tests/vircgroupmock.c | 21 ++++++++++++---------
Pablo Greco 40546a
 1 file changed, 12 insertions(+), 9 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
Pablo Greco 40546a
index 51861be38e..bae8304f6c 100644
Pablo Greco 40546a
--- a/tests/vircgroupmock.c
Pablo Greco 40546a
+++ b/tests/vircgroupmock.c
Pablo Greco 40546a
@@ -468,12 +468,13 @@ FILE *fopen(const char *path, const char *mode)
Pablo Greco 40546a
         if (STREQ(mode, "r")) {
Pablo Greco 40546a
             if (allinone)
Pablo Greco 40546a
                 return fmemopen((void *)procmountsallinone,
Pablo Greco 40546a
-                                strlen(procmountsallinone), mode);
Pablo Greco 40546a
+                                strlen(procmountsallinone) + 1, mode);
Pablo Greco 40546a
             else if (logind)
Pablo Greco 40546a
                 return fmemopen((void *)procmountslogind,
Pablo Greco 40546a
-                                strlen(procmountslogind), mode);
Pablo Greco 40546a
+                                strlen(procmountslogind) + 1, mode);
Pablo Greco 40546a
             else
Pablo Greco 40546a
-                return fmemopen((void *)procmounts, strlen(procmounts), mode);
Pablo Greco 40546a
+                return fmemopen((void *)procmounts,
Pablo Greco 40546a
+                                strlen(procmounts) + 1, mode);
Pablo Greco 40546a
         } else {
Pablo Greco 40546a
             errno = EACCES;
Pablo Greco 40546a
             return NULL;
Pablo Greco 40546a
@@ -483,12 +484,13 @@ FILE *fopen(const char *path, const char *mode)
Pablo Greco 40546a
         if (STREQ(mode, "r")) {
Pablo Greco 40546a
             if (allinone)
Pablo Greco 40546a
                 return fmemopen((void *)proccgroupsallinone,
Pablo Greco 40546a
-                                strlen(proccgroupsallinone), mode);
Pablo Greco 40546a
+                                strlen(proccgroupsallinone) + 1, mode);
Pablo Greco 40546a
             else if (logind)
Pablo Greco 40546a
                 return fmemopen((void *)proccgroupslogind,
Pablo Greco 40546a
-                                strlen(proccgroupslogind), mode);
Pablo Greco 40546a
+                                strlen(proccgroupslogind) + 1, mode);
Pablo Greco 40546a
             else
Pablo Greco 40546a
-                return fmemopen((void *)proccgroups, strlen(proccgroups), mode);
Pablo Greco 40546a
+                return fmemopen((void *)proccgroups,
Pablo Greco 40546a
+                                strlen(proccgroups) + 1, mode);
Pablo Greco 40546a
         } else {
Pablo Greco 40546a
             errno = EACCES;
Pablo Greco 40546a
             return NULL;
Pablo Greco 40546a
@@ -498,12 +500,13 @@ FILE *fopen(const char *path, const char *mode)
Pablo Greco 40546a
         if (STREQ(mode, "r")) {
Pablo Greco 40546a
             if (allinone)
Pablo Greco 40546a
                 return fmemopen((void *)procselfcgroupsallinone,
Pablo Greco 40546a
-                                strlen(procselfcgroupsallinone), mode);
Pablo Greco 40546a
+                                strlen(procselfcgroupsallinone) + 1, mode);
Pablo Greco 40546a
             else if (logind)
Pablo Greco 40546a
                 return fmemopen((void *)procselfcgroupslogind,
Pablo Greco 40546a
-                                strlen(procselfcgroupslogind), mode);
Pablo Greco 40546a
+                                strlen(procselfcgroupslogind) + 1, mode);
Pablo Greco 40546a
             else
Pablo Greco 40546a
-                return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode);
Pablo Greco 40546a
+                return fmemopen((void *)procselfcgroups,
Pablo Greco 40546a
+                                strlen(procselfcgroups) + 1, mode);
Pablo Greco 40546a
         } else {
Pablo Greco 40546a
             errno = EACCES;
Pablo Greco 40546a
             return NULL;
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a