[libvirt] [PATCH] vircgroupmock.c: Avoid crashing if lstat() not found

Michal Privoznik mprivozn at redhat.com
Thu Oct 17 13:33:36 UTC 2013


In init_syms() we admit that stat() may not exists (in favor of existing
__lxstat). However, if previously an library checked for existence of
these two symbols and wisely has chosen the existing one, now, that we've
mocked the both symbols, we are confusing the library. Moreover, such
library will get SIGSEGV immediately after wrong decision, since
reallstat is NULL.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tests/vircgroupmock.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index adc1718..0b44fda 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -542,10 +542,16 @@ int lstat(const char *path, struct stat *sb)
             errno = ENOMEM;
             return -1;
         }
-        ret = reallstat(newpath, sb);
+        if (reallstat)
+            ret = reallstat(newpath, sb);
+        else
+            ret = real__lxstat(_STAT_VER, newpath, sb);
         free(newpath);
     } else {
-        ret = reallstat(path, sb);
+        if (reallstat)
+            ret = reallstat(path, sb);
+        else
+            ret = real__lxstat(_STAT_VER, path, sb);
     }
     return ret;
 }
-- 
1.8.1.5




More information about the libvir-list mailing list