From a86682c57e46b56d1bfdc1d23ca2b6b7ab2eb3ee Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Thu, 6 May 2021 17:08:34 +0200 Subject: [PATCH] tests: virfilemock: realpath: Allow non-null second parameter When other preloaded libraries wrap and / or make calls to `realpath` (e.g. LLVM's AddessSanitizer), the second parameter is no longer guaranteed to be NULL. Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- build-aux/syntax-check.mk | 2 +- tests/virfilemock.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 552d639119..03b7599abc 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1740,7 +1740,7 @@ exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \ exclude_file_name_regexp--sc_po_check = ^(docs/|src/rpc/gendispatch\.pl$$|tests/commandtest.c$$) exclude_file_name_regexp--sc_prohibit_PATH_MAX = \ - ^build-aux/syntax-check\.mk$$ + ^(build-aux/syntax-check\.mk|tests/virfilemock.c)$$ exclude_file_name_regexp--sc_prohibit_access_xok = \ ^(src/util/virutil\.c)$$ diff --git a/tests/virfilemock.c b/tests/virfilemock.c index 7c9174bdd9..bf153ab769 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -24,7 +24,6 @@ #if WITH_LINUX_MAGIC_H # include #endif -#include #include "virmock.h" #include "virstring.h" @@ -186,15 +185,20 @@ realpath(const char *path, char *resolved) if (getenv("LIBVIRT_MTAB")) { const char *p; - char *ret; - assert(resolved == NULL); - if ((p = STRSKIP(path, "/some/symlink"))) - ret = g_strdup_printf("/gluster%s", p); - else - ret = g_strdup(path); + if ((p = STRSKIP(path, "/some/symlink"))) { + if (resolved) + g_snprintf(resolved, PATH_MAX, "/gluster%s", p); + else + resolved = g_strdup_printf("/gluster%s", p); + } else { + if (resolved) + g_strlcpy(resolved, path, PATH_MAX); + else + resolved = g_strdup(path); + } - return ret; + return resolved; } return real_realpath(path, resolved);