1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * This test ensures that ensures that FORTIFY's run-time bits aren't enabled with ASAN on. Most 19 * ways of getting FORTIFY to break turn into UB unless you get creative. Rather than remaking the 20 * entire FORTIFY test-suite with this added constraint, we pick a function with well-defined 21 * behavior when a FORTIFY check would fail (umask), and hope that the success of that is indicative 22 * of the rest working. 23 */ 24 25 #ifndef __clang__ 26 #error "Non-clang isn't supported" 27 #endif 28 29 #ifndef _FORTIFY_SOURCE 30 #error "_FORTIFY_SOURCE must be defined" 31 #endif 32 33 #include <sys/cdefs.h> 34 35 #if defined(__BIONIC__) && __has_feature(address_sanitizer) 36 #include <sys/stat.h> 37 #include <gtest/gtest.h> 38 TEST(ClangFortifyASAN,NoRuntimeChecksAreEnabled)39TEST(ClangFortifyASAN, NoRuntimeChecksAreEnabled) { 40 volatile mode_t unknown = 01000; 41 mode_t previous = umask(unknown); 42 43 // Not necessary, but polite. 44 umask(previous); 45 } 46 #endif 47