]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Resolve possible overrun
authorJohn Ferlan <jferlan@redhat.com>
Thu, 20 Sep 2018 21:34:38 +0000 (17:34 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 24 Sep 2018 12:50:02 +0000 (08:50 -0400)
Coverity noted that each of the fmemopen called used the strlen value
in order to allocate space, but that neglected space for terminating
null string. So just add 1 to the strlen.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
tests/vircgroupmock.c

index d512417789486f5becd94874ec7d5229f834e655..6587fb3c7ecb79e09bba46a000a53ed440052b08 100644 (file)
@@ -466,12 +466,13 @@ FILE *fopen(const char *path, const char *mode)
         if (STREQ(mode, "r")) {
             if (allinone)
                 return fmemopen((void *)procmountsallinone,
-                                strlen(procmountsallinone), mode);
+                                strlen(procmountsallinone) + 1, mode);
             else if (logind)
                 return fmemopen((void *)procmountslogind,
-                                strlen(procmountslogind), mode);
+                                strlen(procmountslogind) + 1, mode);
             else
-                return fmemopen((void *)procmounts, strlen(procmounts), mode);
+                return fmemopen((void *)procmounts,
+                                strlen(procmounts) + 1, mode);
         } else {
             errno = EACCES;
             return NULL;
@@ -481,12 +482,13 @@ FILE *fopen(const char *path, const char *mode)
         if (STREQ(mode, "r")) {
             if (allinone)
                 return fmemopen((void *)proccgroupsallinone,
-                                strlen(proccgroupsallinone), mode);
+                                strlen(proccgroupsallinone) + 1, mode);
             else if (logind)
                 return fmemopen((void *)proccgroupslogind,
-                                strlen(proccgroupslogind), mode);
+                                strlen(proccgroupslogind) + 1, mode);
             else
-                return fmemopen((void *)proccgroups, strlen(proccgroups), mode);
+                return fmemopen((void *)proccgroups,
+                                strlen(proccgroups) + 1, mode);
         } else {
             errno = EACCES;
             return NULL;
@@ -496,12 +498,13 @@ FILE *fopen(const char *path, const char *mode)
         if (STREQ(mode, "r")) {
             if (allinone)
                 return fmemopen((void *)procselfcgroupsallinone,
-                                strlen(procselfcgroupsallinone), mode);
+                                strlen(procselfcgroupsallinone) + 1, mode);
             else if (logind)
                 return fmemopen((void *)procselfcgroupslogind,
-                                strlen(procselfcgroupslogind), mode);
+                                strlen(procselfcgroupslogind) + 1, mode);
             else
-                return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode);
+                return fmemopen((void *)procselfcgroups,
+                                strlen(procselfcgroups) + 1, mode);
         } else {
             errno = EACCES;
             return NULL;