]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add the sanitize blacklist contents to the hash
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 22 Apr 2018 09:49:32 +0000 (11:49 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 7 May 2018 17:50:44 +0000 (19:50 +0200)
src/ccache.c
test/run
test/suites/sanitize_blacklist.bash [new file with mode: 0644]

index bef3369885dc4f8173b2d9c45a558b6bc1d7ab13..c5497dea3fa76688801f7e3a4e1c69d30c950c7c 100644 (file)
@@ -225,6 +225,9 @@ static char *profile_dir = NULL;
 static bool profile_use = false;
 static bool profile_generate = false;
 
+// Sanitize blacklist
+static char *sanitize_blacklist = NULL;
+
 // Whether we are using a precompiled header (either via -include, #include or
 // clang's -include-pch or -include-pth).
 static bool using_precompiled_header = false;
@@ -1655,6 +1658,16 @@ calculate_common_hash(struct args *args, struct mdfour *hash)
                }
        }
 
+       // Possibly hash the sanitize blacklist file path.
+       if (sanitize_blacklist) {
+               cc_log("Hashing sanitize blacklist %s", sanitize_blacklist);
+               hash_delimiter(hash, "sanitizeblacklist");
+               if (!hash_file(hash, sanitize_blacklist)) {
+                       stats_update(STATS_BADEXTRAFILE);
+                       failed();
+               }
+       }
+
        if (!str_eq(conf->extra_files_to_hash, "")) {
                char *p = x_strdup(conf->extra_files_to_hash);
                char *q = p;
@@ -2502,6 +2515,11 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                        args_add(stripped_args, argv[i]);
                        continue;
                }
+               if (str_startswith(argv[i], "-fsanitize-blacklist=")) {
+                       sanitize_blacklist = x_strdup(argv[i] + 21);
+                       args_add(stripped_args, argv[i]);
+                       continue;
+               }
                if (str_startswith(argv[i], "--sysroot=")) {
                        char *relpath = make_relative_path(x_strdup(argv[i] + 10));
                        char *option = format("--sysroot=%s", relpath);
@@ -3207,6 +3225,7 @@ cc_reset(void)
        free(debug_prefix_maps); debug_prefix_maps = NULL;
        debug_prefix_maps_len = 0;
        free(profile_dir); profile_dir = NULL;
+       free(sanitize_blacklist); sanitize_blacklist = NULL;
        free(included_pch_file); included_pch_file = NULL;
        args_free(orig_args); orig_args = NULL;
        free(input_file); input_file = NULL;
index 82a80541049bca92f58c656ccc197fdc59c6d09b..0bbb21c441e5a3cf50e6c0944110d143c8b321c4 100755 (executable)
--- a/test/run
+++ b/test/run
@@ -364,6 +364,7 @@ nocpp2
 cpp1
 multi_arch
 serialize_diagnostics
+sanitize_blacklist
 debug_prefix_map
 masquerading
 hardlink
diff --git a/test/suites/sanitize_blacklist.bash b/test/suites/sanitize_blacklist.bash
new file mode 100644 (file)
index 0000000..a2411e9
--- /dev/null
@@ -0,0 +1,58 @@
+SUITE_sanitize_blacklist_PROBE() {
+    touch test.c blacklist.txt
+    if ! $REAL_COMPILER -c -fsanitize-blacklist=blacklist.txt \
+         test.c 2>/dev/null; then
+        echo "-fsanitize-blacklist not supported by compiler"
+    fi
+}
+
+SUITE_sanitize_blacklist_SETUP() {
+    generate_code 1 test1.c
+    echo "fun:foo" >blacklist.txt
+
+    unset CCACHE_NODIRECT
+}
+
+SUITE_sanitize_blacklist() {
+    # -------------------------------------------------------------------------
+    TEST "Compile OK"
+
+    $REAL_COMPILER -c -fsanitize-blacklist=blacklist.txt test1.c
+
+    $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+
+    $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+
+    echo "fun:bar" >blacklist.txt
+
+    $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache miss' 2
+    expect_stat 'files in cache' 4
+
+    $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache miss' 2
+    expect_stat 'files in cache' 4
+
+    # -------------------------------------------------------------------------
+    TEST "Compile failed"
+
+    if $REAL_COMPILER -c -fsanitize-blacklist=nosuchfile.txt test1.c 2>expected.stderr; then
+        test_failed "Expected an error compiling test1.c"
+    fi
+
+    rm blacklist.txt
+
+    if $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c 2>expected.stderr; then
+        test_failed "Expected an error compiling test1.c"
+    fi
+
+    expect_stat 'error hashing extra file' 1
+}