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


##########
src/fuzzers/cpp/TimeBasedRollingPolicyFuzzer.cpp:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 <fuzzer/FuzzedDataProvider.h>
+#include <log4cxx/patternlayout.h>
+#include <log4cxx/rolling/rollingfileappender.h>
+#include <log4cxx/rolling/timebasedrollingpolicy.h>
+#include <log4cxx/logmanager.h>
+
+#define DATE_PATTERN            "yyyy-MM-dd_HH_mm_ss"
+#define PATTERN_LAYOUT          LOG4CXX_STR("%c{1} - %m%n")
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+using namespace log4cxx::rolling;
+
+// A fuzzer for TimeBasedRollingPolicy
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+    FuzzedDataProvider fdp(data, size);
+
+    // Set up logger
+    Pool            pool;
+    PatternLayoutPtr         layout( new PatternLayout(PATTERN_LAYOUT));
+    RollingFileAppenderPtr  rfa(    new RollingFileAppender());
+    rfa->setAppend(fdp.ConsumeBool());
+    rfa->setLayout(layout);
+
+    TimeBasedRollingPolicyPtr tbrp = TimeBasedRollingPolicyPtr(new 
TimeBasedRollingPolicy());
+    bool usegz = fdp.ConsumeBool();
+    if(usegz) {
+           tbrp->setFileNamePattern(LogString(LOG4CXX_STR("fuzz-%d{" 
DATE_PATTERN "}.gz")));
+    } else {
+           tbrp->setFileNamePattern(LogString(LOG4CXX_STR("fuzz-%d{" 
DATE_PATTERN "}.zip")));
+    }
+    rfa->setFile(LOG4CXX_STR(LOG4CXX_STR("test.log")));
+    
+    tbrp->activateOptions(pool);
+    rfa->setRollingPolicy(tbrp);
+    rfa->activateOptions(pool);
+    rfa->setBufferSize(fdp.ConsumeIntegral<int>());

Review Comment:
   Should be fixed with 
https://github.com/apache/logging-log4cxx/pull/461/commits/3febd7a0c0a43085e7b5cfdf27adcfb856fc8d8b.



-- 
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