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

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@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

On Thu, Oct 17, 2013 at 03:33:36PM +0200, Michal Privoznik wrote:
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.
I don't really get what you're trying to say here. If lstat() doesn't exist in the libraries we're linking to, then our lstat() wrapper should not be called either. Also, what platform do you see a crash on. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Michal Privoznik