From d7e5baa5a1261877cee5617a1c519c2a0afba75c Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 26 Feb 2019 10:12:05 +0100 Subject: [PATCH] virmock: Initialize both symbols in VIR_MOCK_REAL_INIT_ALT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It may happen that both symbols are present. Especially when chaining mocks. For instance if a test is using virpcimock and then both stat and __xstat would be present in the address space as virpcimock implements both. Then, if the test would try to use say virfilewrapper (which again uses VIR_MOCK_REAL_INIT_ALT() to init real_stat and real___xstat) it would find stat() from virpcimock and stop there. The virfilewrapper.c:real___xstat wouldn't be initialized and thus it may result in a segfault. The reason for segfault is that sys/stat.h may redefine stat() to call __xstat(). Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé --- tests/virmock.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/virmock.h b/tests/virmock.h index 853dbb8be2..9c7ecf60ce 100644 --- a/tests/virmock.h +++ b/tests/virmock.h @@ -292,8 +292,9 @@ # define VIR_MOCK_REAL_INIT_ALT(name1, name2) \ do { \ - if (!(real_ ## name1 = dlsym(RTLD_NEXT, #name1)) && \ - !(real_ ## name2 = dlsym(RTLD_NEXT, #name2))) { \ + real_ ## name1 = dlsym(RTLD_NEXT, #name1); \ + real_ ## name2 = dlsym(RTLD_NEXT, #name2); \ + if (!real_##name1 && !real_##name2) { \ fprintf(stderr, "Cannot find real '%s' or '%s' symbol\n", \ #name1, #name2); \ abort(); \