AdamKorcz commented on code in PR #454:
URL: https://github.com/apache/logging-log4cxx/pull/454#discussion_r1921069605


##########
src/fuzzers/cpp/HTMLLayoutFuzzer.cpp:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stdint.h"
+#include <log4cxx/logstring.h>
+#include <log4cxx/ndc.h>
+#include <log4cxx/helpers/stringhelper.h>
+#include <fuzzer/FuzzedDataProvider.h>
+#include <log4cxx/mdc.h>
+#include <log4cxx/htmllayout.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+using namespace log4cxx::spi;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+       // Setup HTMLLayout
+       HTMLLayout layout;
+       log4cxx::helpers::Pool p;
+
+       FuzzedDataProvider fdp(data, size);
+
+       // Optional locationinfo
+       if (fdp.ConsumeBool()) {
+               layout.setOption(LOG4CXX_STR("LOCATIONINFO"), 
LOG4CXX_STR("locationinfo"));
+       }
+       // Optional threadinfo
+       if (fdp.ConsumeBool()) {
+               layout.setOption(LOG4CXX_STR("TITLE"), LOG4CXX_STR("title"));
+       }
+
+       // Header
+       if (fdp.ConsumeBool()) {
+               std::string headerStr = fdp.ConsumeRandomLengthString();
+               layout.appendHeader(LOG4CXX_STR(headerStr), p);
+       }
+
+       // Create random strings we need later
+       std::string key1 = fdp.ConsumeRandomLengthString();
+       std::string val1 = fdp.ConsumeRandomLengthString();
+       std::string key2 = fdp.ConsumeRandomLengthString();
+       std::string val2 = fdp.ConsumeRandomLengthString();
+       std::string key3 = fdp.ConsumeRandomLengthString();
+       std::string val3 = fdp.ConsumeRandomLengthString();
+       std::string key4 = fdp.ConsumeRandomLengthString();
+       std::string val4 = fdp.ConsumeRandomLengthString();
+       std::string ndcMessage = fdp.ConsumeRandomLengthString();
+       std::string loggerStr = fdp.ConsumeRandomLengthString();
+       std::string content = fdp.ConsumeRemainingBytesAsString();

Review Comment:
   That is not the case. The fuzzer determines the length of the string in a 
deterministic manner. It _can_ consist of the entire test case, but those odd 
cases are fine. Ref the doc:
   
   "ConsumeRandomLengthString method returns a std::string as well, but its 
length is derived from the fuzz input and typically is hard to predict, though 
always deterministic. The caller can provide the max length argument."
   
   
https://github.com/google/fuzzing/blob/master/docs/split-inputs.md#methods-for-extracting-sequences-of-bytes
   
   I also tested it locally and found that the non-first invocations of 
`fdp.ConsumeRandomLengthString()` do indeed generate strings.
   
   The one that should always be last is `ConsumeRemainingBytesAsString()`. If 
it is not, then the remaining attempts to generate strings will yield empty 
strings like you say.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to