1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <cstring> 17 #include <string> 18 19 namespace panda::terminate { 20 21 #ifndef FUZZING_EXIT_ON_FAILED_ASSERT_FOR 22 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 23 #define FUZZING_EXIT_ON_FAILED_ASSERT_FOR "" 24 #endif 25 Terminate(const char * file)26[[noreturn]] void Terminate(const char *file) 27 { 28 auto filepath = std::string(file); 29 std::string libsTmp; 30 31 char *replace = std::getenv("FUZZING_EXIT_ON_FAILED_ASSERT"); 32 if ((replace != nullptr) && (std::string(replace) == "false")) { 33 std::abort(); 34 } 35 36 char *libs = std::getenv("FUZZING_EXIT_ON_FAILED_ASSERT_FOR"); 37 if (libs == nullptr) { 38 libsTmp = std::string(FUZZING_EXIT_ON_FAILED_ASSERT_FOR); 39 if (libsTmp.empty()) { 40 std::abort(); 41 } 42 libs = libsTmp.data(); 43 } 44 45 char *lib = strtok(libs, ","); 46 while (lib != nullptr) { 47 if (filepath.find(lib) != std::string::npos) { 48 std::exit(1); 49 } 50 lib = strtok(nullptr, ","); 51 } 52 std::abort(); 53 } 54 55 } // namespace panda::terminate 56