]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-mountpoint-util: unpoison string allocated by sscanf %ms
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 22 Feb 2019 12:23:57 +0000 (13:23 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 25 Feb 2019 09:07:18 +0000 (10:07 +0100)
src/test/test-mountpoint-util.c

index 8e45c0b1a7a8a167968c2658770a20c1caa49fbf..be7642950653e7018260184eab26048eab9f2c6a 100644 (file)
@@ -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) {