]>
git.ipfire.org Git - thirdparty/openssl.git/blob - fuzz/test-corpus.c
2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 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 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
12 * Given a list of files, run each of them through the fuzzer. Note that
13 * failure will be indicated by some kind of crash. Switching on things like
14 * asan improves the test.
21 #include <openssl/crypto.h>
23 #include "internal/o_dir.h"
25 #if defined(_WIN32) && defined(_MAX_PATH) && !defined(PATH_MAX)
26 # define PATH_MAX _MAX_PATH
30 # define PATH_MAX 4096
33 # if !defined(S_ISREG)
34 # define S_ISREG(m) ((m) & S_IFREG)
37 static void testfile(const char *pathname
)
44 if (stat(pathname
, &st
) < 0 || !S_ISREG(st
.st_mode
))
46 printf("# %s\n", pathname
);
48 f
= fopen(pathname
, "rb");
51 buf
= malloc(st
.st_size
);
53 s
= fread(buf
, 1, st
.st_size
, f
);
54 OPENSSL_assert(s
== (size_t)st
.st_size
);
55 FuzzerTestOneInput(buf
, s
);
61 int main(int argc
, char **argv
) {
64 FuzzerInitialize(&argc
, &argv
);
66 for (n
= 1; n
< argc
; ++n
) {
67 size_t dirname_len
= strlen(argv
[n
]);
68 const char *filename
= NULL
;
69 char *pathname
= NULL
;
70 OPENSSL_DIR_CTX
*ctx
= NULL
;
74 * We start with trying to read the given path as a directory.
76 while ((filename
= OPENSSL_DIR_read(&ctx
, argv
[n
])) != NULL
) {
78 if (pathname
== NULL
) {
79 pathname
= malloc(PATH_MAX
);
82 strcpy(pathname
, argv
[n
]);
84 if (strchr(":<]", pathname
[dirname_len
- 1]) == NULL
)
86 pathname
[dirname_len
++] = '/';
87 pathname
[dirname_len
] = '\0';
89 strcpy(pathname
+ dirname_len
, filename
);
92 OPENSSL_DIR_end(&ctx
);
94 /* If it wasn't a directory, treat it as a file instead */