test_z85_decode_fuzzer.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifdef ZMQ_USE_FUZZING_ENGINE
4 #include <fuzzer/FuzzedDataProvider.h>
5 #endif
6 
7 #include <string>
8 #include <stdlib.h>
9 
10 #include "testutil.hpp"
11 #include "testutil_unity.hpp"
12 
13 extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
14 {
15  uint8_t *secret_key;
16 
17  if (size < 5)
18  return 0;
19 
20  // As per API definition, input must be divisible by 5, so truncate it if it's not
21  size -= size % 5;
22  // As per API definition, the destination must be at least 0.8 times the input data
23  TEST_ASSERT_NOT_NULL (secret_key = (uint8_t *) malloc (size * 4 / 5));
24 
25  std::string z85_secret_key (reinterpret_cast<const char *> (data), size);
26  zmq_z85_decode (secret_key, z85_secret_key.c_str ());
27 
28  free (secret_key);
29 
30  return 0;
31 }
32 
33 #ifndef ZMQ_USE_FUZZING_ENGINE
35 {
36  uint8_t **data;
37  size_t *len, num_cases = 0;
39  "tests/libzmq-fuzz-corpora/test_z85_decode_fuzzer_seed_corpus", &data,
40  &len, &num_cases)
41  != 0)
42  exit (77);
43 
44  while (num_cases-- > 0) {
46  LLVMFuzzerTestOneInput (data[num_cases], len[num_cases]));
47  free (data[num_cases]);
48  }
49 
50  free (data);
51  free (len);
52 }
53 
54 int main (int argc, char **argv)
55 {
57 
58  UNITY_BEGIN ();
60 
61  return UNITY_END ();
62 }
63 #endif
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: test_z85_decode_fuzzer.cpp:13
zmq_z85_decode
ZMQ_EXPORT uint8_t * zmq_z85_decode(uint8_t *dest_, const char *string_)
Definition: zmq_utils.cpp:135
UNITY_END
return UNITY_END()
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
testutil_unity.hpp
fuzzer_corpus_encode
int fuzzer_corpus_encode(const char *dirname, uint8_t ***data, size_t **len, size_t *num_cases)
Definition: testutil.cpp:534
testutil.hpp
test_z85_decode_fuzzer
void test_z85_decode_fuzzer()
Definition: test_z85_decode_fuzzer.cpp:34
main
int main(int argc, char **argv)
Definition: test_z85_decode_fuzzer.cpp:54
len
int len
Definition: php/ext/google/protobuf/map.c:206
size
GLsizeiptr size
Definition: glcorearb.h:2943
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879
TEST_ASSERT_NOT_NULL
#define TEST_ASSERT_NOT_NULL(pointer)
Definition: unity.h:125
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59