/src/openssl41/fuzz/pkcs7_verify.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
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. |
9 | | */ |
10 | | #include <limits.h> |
11 | | #include <openssl/bio.h> |
12 | | #include <openssl/err.h> |
13 | | #include <openssl/pkcs7.h> |
14 | | #include "fuzzer.h" |
15 | | |
16 | | int FuzzerInitialize(int *argc, char ***argv) |
17 | 229 | { |
18 | 229 | return 1; |
19 | 229 | } |
20 | | |
21 | | int FuzzerTestOneInput(const uint8_t *buf, size_t len) |
22 | 5.97k | { |
23 | 5.97k | BIO *indata = NULL; |
24 | 5.97k | BIO *out = NULL; |
25 | 5.97k | PKCS7 *p7 = NULL; |
26 | 5.97k | const unsigned char *in; |
27 | 5.97k | size_t consumed; |
28 | 5.97k | size_t remaining; |
29 | | |
30 | 5.97k | if (len > LONG_MAX) |
31 | 0 | return 0; |
32 | | |
33 | 5.97k | in = buf; |
34 | 5.97k | p7 = d2i_PKCS7(NULL, &in, (long)len); |
35 | 5.97k | if (p7 == NULL) |
36 | 3.42k | goto err; |
37 | | |
38 | 2.55k | consumed = (size_t)(in - buf); |
39 | 2.55k | remaining = len - consumed; |
40 | 2.55k | if (remaining > INT_MAX) |
41 | 0 | goto err; |
42 | | |
43 | 2.55k | if (consumed < len) { |
44 | 2.26k | indata = BIO_new_mem_buf(in, (int)remaining); |
45 | 2.26k | if (indata == NULL) |
46 | 0 | goto err; |
47 | 2.26k | } |
48 | | |
49 | 2.55k | out = BIO_new(BIO_s_null()); |
50 | 2.55k | if (out == NULL) |
51 | 0 | goto err; |
52 | | |
53 | 2.55k | PKCS7_verify(p7, NULL, NULL, indata, out, PKCS7_NOVERIFY); |
54 | | |
55 | 5.97k | err: |
56 | 5.97k | BIO_free(out); |
57 | 5.97k | PKCS7_free(p7); |
58 | 5.97k | BIO_free(indata); |
59 | 5.97k | ERR_clear_error(); |
60 | 5.97k | return 0; |
61 | 2.55k | } |
62 | | |
63 | | void FuzzerCleanup(void) |
64 | 0 | { |
65 | 0 | } |