]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: don't abort in fopen(/proc/mounts)
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 26 Mar 2019 14:55:36 +0000 (14:55 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 27 Mar 2019 16:11:34 +0000 (16:11 +0000)
The mock fopen() function will abort if "/proc/mounts" is
requested with "r" permissions and VIR_CGROUP_MOCK_FILENAME
env var is not set.

Unfortunately this is triggering by the libselinux library
constructor when it tries to read /proc/mounts to find out
if selinuxfs is mounted in an unusual place.

This, however, only affects libselinux in Debian as that
opens with "r", while in Fedora / RHEL it opens "re" and
thus luckily never triggered the abort(), instead getting
an EACCESS.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
tests/vircgroupmock.c

index 06bd0a5f29821cb6a3d899822dfd150d424d9fb6..9c67a44b0df10f5692d4fc43c8bc98b52b09d9a9 100644 (file)
@@ -460,8 +460,10 @@ FILE *fopen(const char *path, const char *mode)
     }
 
     if (type) {
-        if (!filename)
-            abort();
+        if (!filename) {
+            errno = EACCES;
+            return NULL;
+        }
         if (virAsprintfQuiet(&filepath, "%s/vircgroupdata/%s.%s",
                              abs_srcdir, filename, type) < 0) {
             abort();