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