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