From 9003da29631b5348a4578d605e150321adbd3461 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 22 Feb 2019 13:23:57 +0100 Subject: [PATCH] test-mountpoint-util: unpoison string allocated by sscanf %ms --- src/test/test-mountpoint-util.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index 8e45c0b1a7..be76429506 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -36,7 +36,7 @@ static void test_mount_propagation_flags(const char *name, int ret, unsigned lon static void test_mnt_id(void) { _cleanup_fclose_ FILE *f = NULL; - Hashmap *h; + _cleanup_hashmap_free_free_ Hashmap *h = NULL; Iterator i; char *p; void *k; @@ -57,7 +57,14 @@ static void test_mnt_id(void) { assert_se(r > 0); assert_se(sscanf(line, "%i %*s %*s %*s %ms", &mnt_id, &path) == 2); - +#if HAS_FEATURE_MEMORY_SANITIZER + /* We don't know the length of the string, so we need to unpoison it one char at a time */ + for (const char *c = path; ;c++) { + msan_unpoison(c, 1); + if (!*c) + break; + } +#endif log_debug("mountinfo: %s → %i", path, mnt_id); assert_se(hashmap_put(h, INT_TO_PTR(mnt_id), path) >= 0); @@ -84,8 +91,6 @@ static void test_mnt_id(void) { log_debug("the other path for mnt id %i is %s\n", mnt_id2, t); assert_se(path_equal(p, t)); } - - hashmap_free_free(h); } static void test_path_is_mount_point(void) { -- 2.25.1