1 // © 2019 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 4 #include <fstream> 5 #include <iostream> 6 #include <sstream> 7 #include <stddef.h> 8 #include <stdint.h> 9 #include <string> 10 11 #include "cmemory.h" 12 13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); 14 main(int argc,char * argv[])15int main(int argc, char* argv[]) 16 { 17 bool show_warning = true; 18 bool show_error = true; 19 #if UPRV_HAS_FEATURE(address_sanitizer) 20 show_warning = false; 21 #endif 22 #if UPRV_HAS_FEATURE(memory_sanitizer) 23 show_warning = false; 24 #endif 25 if (argc > 2 && strcmp(argv[2], "-q") == 0) { 26 show_warning = false; 27 show_error = false; 28 } 29 if (show_warning) { 30 std::cerr << "WARNING: This binary work only under build configure with" << std::endl 31 << " CFLAGS=\"-fsanitize=$SANITIZE\"" 32 << " CXXFLAGS=\"-fsanitize=$SANITIZE\"" 33 << " ./runConfigureICU ... " << std::endl 34 << " where $SANITIZE is 'address' or 'memory'" << std::endl 35 << "Plesae run the above step and make tests to rebuild" << std::endl; 36 // Do not return -1 here so we will pass the unit test. 37 } 38 if (argc < 2) { 39 if (show_error) { 40 std::cerr << "Usage: " << argv[0] << " testcasefile [-q]" << std::endl 41 << " -q : quiet while error" << std::endl; 42 } 43 return -1; 44 } 45 const char *path = argv[1]; 46 std::ifstream file(path, std::ios::binary); 47 if (!file.is_open()) { 48 if (show_error) { 49 std::cerr << "Cannot open testcase file " << path << std::endl; 50 } 51 return -1; 52 } 53 std::ostringstream ostrm; 54 ostrm << file.rdbuf(); 55 LLVMFuzzerTestOneInput((const uint8_t *) ostrm.str().c_str(), ostrm.str().size()); 56 57 return 0; 58 } 59