Coverage Report

Created: 2025-07-11 06:21

/src/buffer_fuzzer.cc
Line
Count
Source
1
/* Copyright 2023 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
13
#include <stddef.h>
14
#include <stdint.h>
15
#include <stdlib.h>
16
#include <string>
17
#include <sys/socket.h>
18
19
#include <fuzzer/FuzzedDataProvider.h>
20
21
extern "C" {
22
#include "libevent/include/event2/event.h"
23
#include "libevent/include/event2/buffer.h"
24
#include "libevent/include/event2/buffer_compat.h"
25
#include "libevent/include/event2/util.h"
26
#include "util-internal.h"
27
}
28
29
882
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
882
  FuzzedDataProvider data_provider(data, size);
31
32
882
  std::string s1 = data_provider.ConsumeRandomLengthString();
33
882
  std::string s2 = data_provider.ConsumeRandomLengthString();
34
882
  std::string s3 = data_provider.ConsumeRandomLengthString();
35
882
  std::string s4 = data_provider.ConsumeRandomLengthString();
36
37
882
  struct evbuffer *buf = evbuffer_new();
38
882
  size_t sz;
39
882
  evbuffer_add(buf, s1.c_str(), s1.size());
40
882
  char *cp = NULL;
41
882
  cp = evbuffer_readln(buf, &sz, EVBUFFER_EOL_ANY);
42
882
  if (cp != NULL) {
43
495
    free(cp);
44
495
    cp = NULL;
45
495
  }
46
882
  struct evbuffer *buf2 = evbuffer_new();
47
882
  struct evbuffer *buf3 = evbuffer_new();
48
882
  struct evbuffer_iovec vec[1];
49
50
882
  evbuffer_add(buf2, s1.c_str(), s1.size());
51
882
  evbuffer_add_reference(buf2, s2.c_str(), s2.size(), NULL, NULL);
52
882
  evbuffer_add_buffer(buf, buf2);
53
882
  evbuffer_expand(buf, 2000);
54
882
  evbuffer_pullup(buf, 2);
55
882
  evbuffer_prepend(buf, s3.c_str(), s3.size());
56
882
  evbuffer_prepend_buffer(buf, buf2);
57
882
  evbuffer_find(buf2, (const unsigned char *)s4.c_str(), s4.size());
58
882
  evbuffer_commit_space(buf, vec, 1);
59
882
  evbuffer_add_buffer_reference(buf, buf2);
60
882
  evbuffer_remove_buffer(buf, buf3, 10);
61
62
882
  evbuffer_free(buf);
63
882
  evbuffer_free(buf2);
64
882
  evbuffer_free(buf3);
65
66
882
  return 0;
67
882
}