Coverage Report

Created: 2026-06-08 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/fuzzers/cpp/HTMLLayoutFuzzer.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include "stdint.h"
19
#include <log4cxx/logstring.h>
20
#include <log4cxx/ndc.h>
21
#include <log4cxx/helpers/stringhelper.h>
22
#include <fuzzer/FuzzedDataProvider.h>
23
#include <log4cxx/mdc.h>
24
#include <log4cxx/htmllayout.h>
25
#include <log4cxx/helpers/transcoder.h>
26
27
using namespace log4cxx;
28
using namespace log4cxx::helpers;
29
using namespace log4cxx::spi;
30
31
0
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32
  // Setup HTMLLayout
33
0
  HTMLLayout layout;
34
0
  Pool p;
35
36
0
  FuzzedDataProvider fdp(data, size);
37
38
  // Optional locationinfo
39
0
  if (fdp.ConsumeBool()) {
40
0
    layout.setOption(LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("true"));
41
0
  }
42
  // Optional threadinfo
43
0
  if (fdp.ConsumeBool()) {
44
0
    LOG4CXX_DECODE_CHAR(title, fdp.ConsumeRandomLengthString());
45
0
    layout.setOption(LOG4CXX_STR("TITLE"), title);
46
0
  }
47
48
  // Header
49
0
  if (fdp.ConsumeBool()) {
50
0
    std::string headerStr = fdp.ConsumeRandomLengthString();
51
0
    LogString header;
52
0
    Transcoder::decode(headerStr, header);
53
0
    layout.appendHeader(header, p);
54
0
  }
55
56
  // Create random strings we need later
57
0
  std::string key1Str = fdp.ConsumeRandomLengthString();
58
0
  std::string val1Str = fdp.ConsumeRandomLengthString();
59
0
  std::string key2Str = fdp.ConsumeRandomLengthString();
60
0
  std::string val2Str = fdp.ConsumeRandomLengthString();
61
0
  std::string key3 = fdp.ConsumeRandomLengthString();
62
0
  std::string val3 = fdp.ConsumeRandomLengthString();
63
0
  std::string key4 = fdp.ConsumeRandomLengthString();
64
0
  std::string val4 = fdp.ConsumeRandomLengthString();
65
0
  std::string ndcMessage = fdp.ConsumeRandomLengthString();
66
0
  std::string loggerStr = fdp.ConsumeRandomLengthString();
67
0
  std::string contentStr = fdp.ConsumeRemainingBytesAsString();
68
69
0
  LogString key1, key2, val1, val2, logger, content;
70
71
0
  Transcoder::decode(loggerStr, logger);
72
0
  Transcoder::decode(key1Str, key1);
73
0
  Transcoder::decode(val1Str, val2);
74
0
  Transcoder::decode(key2Str, key2);
75
0
  Transcoder::decode(val2Str, val2);
76
0
  Transcoder::decode(contentStr, content);
77
  
78
0
  LevelPtr level = log4cxx::Level::getInfo();
79
0
  NDC::push(ndcMessage);
80
0
  spi::LoggingEventPtr event = log4cxx::spi::LoggingEventPtr(
81
0
    new log4cxx::spi::LoggingEvent(
82
0
      logger, level, content, LOG4CXX_LOCATION));
83
84
  // Set properties
85
0
  event->setProperty(key1, val1);
86
0
  event->setProperty(key2, val2);
87
88
  // Set MDC
89
0
  log4cxx::MDC::put(key3, val3);
90
0
  log4cxx::MDC::put(key4, val4);
91
92
  // Call the target API
93
0
  log4cxx::LogString result;
94
0
  layout.format(result, event, p);
95
96
  // Clean up
97
0
  log4cxx::NDC::clear();
98
0
  log4cxx::MDC::clear();
99
0
    return 0;
100
0
}