Coverage Report

Created: 2026-09-14 06:53

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
namespace
32
{
33
  const int MaxKeyLength = 50;
34
  const int MaxValueLength = 500;
35
  const int MaxMessageLength = 2000;
36
}
37
38
17.6k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
  // Setup HTMLLayout
40
17.6k
  HTMLLayout layout;
41
42
17.6k
  FuzzedDataProvider fdp(data, size);
43
44
  // Optional locationinfo
45
17.6k
  if (fdp.ConsumeBool()) {
46
10.1k
    layout.setOption(LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("true"));
47
10.1k
  }
48
  // Optional threadinfo
49
17.6k
  if (fdp.ConsumeBool()) {
50
8.52k
    LOG4CXX_DECODE_CHAR(title, fdp.ConsumeRandomLengthString(MaxValueLength));
51
8.52k
    layout.setOption(LOG4CXX_STR("TITLE"), title);
52
8.52k
  }
53
54
  // Header
55
17.6k
  if (fdp.ConsumeBool()) {
56
7.99k
    std::string headerStr = fdp.ConsumeRandomLengthString(MaxValueLength);
57
7.99k
    LogString header;
58
7.99k
    Transcoder::decode(headerStr, header);
59
7.99k
    layout.appendHeader(header);
60
7.99k
  }
61
62
  // Create random strings we need later
63
17.6k
  std::string key1Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
64
17.6k
  std::string val1Str = fdp.ConsumeRandomLengthString(MaxValueLength);
65
17.6k
  std::string key2Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
66
17.6k
  std::string val2Str = fdp.ConsumeRandomLengthString(MaxValueLength);
67
17.6k
  std::string key3 = fdp.ConsumeRandomLengthString(MaxKeyLength);
68
17.6k
  std::string val3 = fdp.ConsumeRandomLengthString(MaxValueLength);
69
17.6k
  std::string key4 = fdp.ConsumeRandomLengthString(MaxKeyLength);
70
17.6k
  std::string val4 = fdp.ConsumeRandomLengthString(MaxValueLength);
71
17.6k
  std::string ndcMessage = fdp.ConsumeRandomLengthString(MaxKeyLength);
72
17.6k
  std::string loggerStr = fdp.ConsumeRandomLengthString(MaxKeyLength);
73
17.6k
  std::string contentStr = fdp.ConsumeRemainingBytesAsString();
74
75
17.6k
  LogString key1, key2, val1, val2, logger, content;
76
77
17.6k
  Transcoder::decode(loggerStr, logger);
78
17.6k
  Transcoder::decode(key1Str, key1);
79
17.6k
  Transcoder::decode(val1Str, val2);
80
17.6k
  Transcoder::decode(key2Str, key2);
81
17.6k
  Transcoder::decode(val2Str, val2);
82
17.6k
  Transcoder::decode(contentStr, content);
83
  
84
17.6k
  LevelPtr level = log4cxx::Level::getInfo();
85
17.6k
  NDC::push(ndcMessage);
86
17.6k
  spi::LoggingEventPtr event = log4cxx::spi::LoggingEventPtr(
87
17.6k
    new log4cxx::spi::LoggingEvent(
88
17.6k
      logger, level, content, LOG4CXX_LOCATION));
89
90
  // Set properties
91
17.6k
  event->setProperty(key1, val1);
92
17.6k
  event->setProperty(key2, val2);
93
94
  // Set MDC
95
17.6k
  log4cxx::MDC::put(key3, val3);
96
17.6k
  log4cxx::MDC::put(key4, val4);
97
98
  // Call the target API
99
17.6k
  log4cxx::LogString result;
100
17.6k
  layout.format(result, event);
101
102
  // Clean up
103
17.6k
  log4cxx::NDC::clear();
104
17.6k
  log4cxx::MDC::clear();
105
17.6k
    return 0;
106
17.6k
}
LLVMFuzzerTestOneInput
Line
Count
Source
38
8.83k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
  // Setup HTMLLayout
40
8.83k
  HTMLLayout layout;
41
42
8.83k
  FuzzedDataProvider fdp(data, size);
43
44
  // Optional locationinfo
45
8.83k
  if (fdp.ConsumeBool()) {
46
5.05k
    layout.setOption(LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("true"));
47
5.05k
  }
48
  // Optional threadinfo
49
8.83k
  if (fdp.ConsumeBool()) {
50
4.26k
    LOG4CXX_DECODE_CHAR(title, fdp.ConsumeRandomLengthString(MaxValueLength));
51
4.26k
    layout.setOption(LOG4CXX_STR("TITLE"), title);
52
4.26k
  }
53
54
  // Header
55
8.83k
  if (fdp.ConsumeBool()) {
56
3.99k
    std::string headerStr = fdp.ConsumeRandomLengthString(MaxValueLength);
57
3.99k
    LogString header;
58
3.99k
    Transcoder::decode(headerStr, header);
59
3.99k
    layout.appendHeader(header);
60
3.99k
  }
61
62
  // Create random strings we need later
63
8.83k
  std::string key1Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
64
8.83k
  std::string val1Str = fdp.ConsumeRandomLengthString(MaxValueLength);
65
8.83k
  std::string key2Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
66
8.83k
  std::string val2Str = fdp.ConsumeRandomLengthString(MaxValueLength);
67
8.83k
  std::string key3 = fdp.ConsumeRandomLengthString(MaxKeyLength);
68
8.83k
  std::string val3 = fdp.ConsumeRandomLengthString(MaxValueLength);
69
8.83k
  std::string key4 = fdp.ConsumeRandomLengthString(MaxKeyLength);
70
8.83k
  std::string val4 = fdp.ConsumeRandomLengthString(MaxValueLength);
71
8.83k
  std::string ndcMessage = fdp.ConsumeRandomLengthString(MaxKeyLength);
72
8.83k
  std::string loggerStr = fdp.ConsumeRandomLengthString(MaxKeyLength);
73
8.83k
  std::string contentStr = fdp.ConsumeRemainingBytesAsString();
74
75
8.83k
  LogString key1, key2, val1, val2, logger, content;
76
77
8.83k
  Transcoder::decode(loggerStr, logger);
78
8.83k
  Transcoder::decode(key1Str, key1);
79
8.83k
  Transcoder::decode(val1Str, val2);
80
8.83k
  Transcoder::decode(key2Str, key2);
81
8.83k
  Transcoder::decode(val2Str, val2);
82
8.83k
  Transcoder::decode(contentStr, content);
83
  
84
8.83k
  LevelPtr level = log4cxx::Level::getInfo();
85
8.83k
  NDC::push(ndcMessage);
86
8.83k
  spi::LoggingEventPtr event = log4cxx::spi::LoggingEventPtr(
87
8.83k
    new log4cxx::spi::LoggingEvent(
88
8.83k
      logger, level, content, LOG4CXX_LOCATION));
89
90
  // Set properties
91
8.83k
  event->setProperty(key1, val1);
92
8.83k
  event->setProperty(key2, val2);
93
94
  // Set MDC
95
8.83k
  log4cxx::MDC::put(key3, val3);
96
8.83k
  log4cxx::MDC::put(key4, val4);
97
98
  // Call the target API
99
8.83k
  log4cxx::LogString result;
100
8.83k
  layout.format(result, event);
101
102
  // Clean up
103
8.83k
  log4cxx::NDC::clear();
104
8.83k
  log4cxx::MDC::clear();
105
8.83k
    return 0;
106
8.83k
}
LLVMFuzzerTestOneInput
Line
Count
Source
38
8.83k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
  // Setup HTMLLayout
40
8.83k
  HTMLLayout layout;
41
42
8.83k
  FuzzedDataProvider fdp(data, size);
43
44
  // Optional locationinfo
45
8.83k
  if (fdp.ConsumeBool()) {
46
5.05k
    layout.setOption(LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("true"));
47
5.05k
  }
48
  // Optional threadinfo
49
8.83k
  if (fdp.ConsumeBool()) {
50
4.26k
    LOG4CXX_DECODE_CHAR(title, fdp.ConsumeRandomLengthString(MaxValueLength));
51
4.26k
    layout.setOption(LOG4CXX_STR("TITLE"), title);
52
4.26k
  }
53
54
  // Header
55
8.83k
  if (fdp.ConsumeBool()) {
56
3.99k
    std::string headerStr = fdp.ConsumeRandomLengthString(MaxValueLength);
57
3.99k
    LogString header;
58
3.99k
    Transcoder::decode(headerStr, header);
59
3.99k
    layout.appendHeader(header);
60
3.99k
  }
61
62
  // Create random strings we need later
63
8.83k
  std::string key1Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
64
8.83k
  std::string val1Str = fdp.ConsumeRandomLengthString(MaxValueLength);
65
8.83k
  std::string key2Str = fdp.ConsumeRandomLengthString(MaxKeyLength);
66
8.83k
  std::string val2Str = fdp.ConsumeRandomLengthString(MaxValueLength);
67
8.83k
  std::string key3 = fdp.ConsumeRandomLengthString(MaxKeyLength);
68
8.83k
  std::string val3 = fdp.ConsumeRandomLengthString(MaxValueLength);
69
8.83k
  std::string key4 = fdp.ConsumeRandomLengthString(MaxKeyLength);
70
8.83k
  std::string val4 = fdp.ConsumeRandomLengthString(MaxValueLength);
71
8.83k
  std::string ndcMessage = fdp.ConsumeRandomLengthString(MaxKeyLength);
72
8.83k
  std::string loggerStr = fdp.ConsumeRandomLengthString(MaxKeyLength);
73
8.83k
  std::string contentStr = fdp.ConsumeRemainingBytesAsString();
74
75
8.83k
  LogString key1, key2, val1, val2, logger, content;
76
77
8.83k
  Transcoder::decode(loggerStr, logger);
78
8.83k
  Transcoder::decode(key1Str, key1);
79
8.83k
  Transcoder::decode(val1Str, val2);
80
8.83k
  Transcoder::decode(key2Str, key2);
81
8.83k
  Transcoder::decode(val2Str, val2);
82
8.83k
  Transcoder::decode(contentStr, content);
83
  
84
8.83k
  LevelPtr level = log4cxx::Level::getInfo();
85
8.83k
  NDC::push(ndcMessage);
86
8.83k
  spi::LoggingEventPtr event = log4cxx::spi::LoggingEventPtr(
87
8.83k
    new log4cxx::spi::LoggingEvent(
88
8.83k
      logger, level, content, LOG4CXX_LOCATION));
89
90
  // Set properties
91
8.83k
  event->setProperty(key1, val1);
92
8.83k
  event->setProperty(key2, val2);
93
94
  // Set MDC
95
8.83k
  log4cxx::MDC::put(key3, val3);
96
8.83k
  log4cxx::MDC::put(key4, val4);
97
98
  // Call the target API
99
8.83k
  log4cxx::LogString result;
100
8.83k
  layout.format(result, event);
101
102
  // Clean up
103
8.83k
  log4cxx::NDC::clear();
104
8.83k
  log4cxx::MDC::clear();
105
8.83k
    return 0;
106
8.83k
}