1 1.1 christos /* 2 1.1 christos * Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1 christos #include <string.h> 11 1.1 christos #include <openssl/bio.h> 12 1.1 christos #include <openssl/crypto.h> 13 1.1 christos 14 1.1 christos #include "testutil.h" 15 1.1 christos 16 1.1 christos /* __has_feature is a clang-ism, while __SANITIZE_ADDRESS__ is a gcc-ism */ 17 1.1 christos #if defined(__has_feature) 18 1.1.1.2 christos #if __has_feature(address_sanitizer) 19 1.1.1.2 christos #define __SANITIZE_ADDRESS__ 1 20 1.1.1.2 christos #endif 21 1.1 christos #endif 22 1.1 christos /* If __SANITIZE_ADDRESS__ isn't defined, define it to be false */ 23 1.1 christos /* Leak detection is not yet supported with MSVC on Windows, so */ 24 1.1 christos /* set __SANITIZE_ADDRESS__ to false in this case as well. */ 25 1.1 christos #if !defined(__SANITIZE_ADDRESS__) || defined(_MSC_VER) 26 1.1.1.2 christos #undef __SANITIZE_ADDRESS__ 27 1.1.1.2 christos #define __SANITIZE_ADDRESS__ 0 28 1.1 christos #endif 29 1.1 christos 30 1.1 christos /* 31 1.1 christos * We use a proper main function here instead of the custom main from the 32 1.1 christos * test framework to avoid CRYPTO_mem_leaks stuff. 33 1.1 christos */ 34 1.1 christos 35 1.1 christos int main(int argc, char *argv[]) 36 1.1 christos { 37 1.1 christos #if __SANITIZE_ADDRESS__ 38 1.1 christos int exitcode = EXIT_SUCCESS; 39 1.1 christos #else 40 1.1 christos /* 41 1.1 christos * When we don't sanitize, we set the exit code to what we would expect 42 1.1 christos * to get when we are sanitizing. This makes it easy for wrapper scripts 43 1.1 christos * to detect that we get the result we expect. 44 1.1 christos */ 45 1.1 christos int exitcode = EXIT_FAILURE; 46 1.1 christos #endif 47 1.1 christos char *volatile lost; 48 1.1 christos 49 1.1 christos lost = OPENSSL_malloc(3); 50 1.1 christos if (!TEST_ptr(lost)) 51 1.1 christos return EXIT_FAILURE; 52 1.1 christos 53 1.1 christos strcpy(lost, "ab"); 54 1.1 christos 55 1.1 christos if (argv[1] && strcmp(argv[1], "freeit") == 0) { 56 1.1 christos OPENSSL_free(lost); 57 1.1 christos exitcode = EXIT_SUCCESS; 58 1.1 christos } 59 1.1 christos 60 1.1 christos lost = NULL; 61 1.1 christos return exitcode; 62 1.1 christos } 63