Skip to content

Commit

Permalink
fix fuzz-47093 by remove use of backslash escaping
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Aug 7, 2022
1 parent 1323e8e commit f55029a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
4 changes: 4 additions & 0 deletions logback-classic/src/test/input/joran/ossfuzz/fuzz-47093.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<configuration>
<variable scope="context" name="fuzz-47093-a" value="a\t"/>
<variable scope="context" name="fuzz-47093-b" value="a\\"/>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,24 @@ public void ossFuzz_46697() throws JoranException {

checker.assertContainsMatch(Status.ERROR, ErrorCodes.EMPTY_MODEL_STACK);
StatusPrinter.print(loggerContext);
}

}

// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47093
// In previous versions of the code, there
@Test
public void ossFuzz_47093() throws JoranException {
System.out.println("==========");
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "ossfuzz/fuzz-47093.xml");

assertEquals("a\\t", loggerContext.getProperty("fuzz-47093-a"));
assertEquals("a\\\\", loggerContext.getProperty("fuzz-47093-b"));


//checker.assertContainsMatch(Status.ERROR, ErrorCodes.EMPTY_MODEL_STACK);
StatusPrinter.print(loggerContext);
}


// @Test
// public void doTest() throws JoranException {
// int LIMIT = 0;
Expand Down
5 changes: 5 additions & 0 deletions logback-core/src/main/java/ch/qos/logback/core/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public interface Context extends PropertyContainer {
*/
void register(LifeCycle component);

/**
* Add scheduledFuture parameter to the list of known futures.
*
* @param scheduledFuture
*/
void addScheduledFuture(ScheduledFuture<?> scheduledFuture);

SequenceNumberGenerator getSequenceNumberGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public void handle(ModelInterpretationContext interpretationContext, Model model
}
}
} else if (checkValueNameAttributesSanity(propertyModel)) {
String value = RegularEscapeUtil.basicEscape(propertyModel.getValue());
// earlier versions performed Java '\' escapes for '\\' '\t' etc. Howevver, there is no
// need to do this. See RegularEscapeUtil.__UNUSED__basicEscape
String value = propertyModel.getValue();

// now remove both leading and trailing spaces
value = value.trim();
value = interpretationContext.subst(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ String formatEscapeCharsForListing(String escapeChars) {
return commaSeperatedEscapeChars.toString();
}

// s might be path such as c:\\toto\\file.log
// as of version 1.3.0-beta1 this method is no longer used
public static String basicEscape(String s) {
char c;
int len = s.length();
Expand All @@ -64,7 +66,7 @@ public static String basicEscape(String s) {
int i = 0;
while (i < len) {
c = s.charAt(i++);
if (c == '\\') {
if (c == '\\' && i < len ) {
c = s.charAt(i++);
if (c == 'n') {
c = '\n';
Expand All @@ -83,9 +85,10 @@ public static String basicEscape(String s) {
} else if (c == '\\') {
c = '\\';
}
/////
}
sbuf.append(c);
}
} // while
return sbuf.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2022, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.pattern.util;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class RegularEscapeUtilTest {


@Before
public void setUp() throws Exception {
}

@Test
public void basicEscape() {
assertEquals("a", RegularEscapeUtil.basicEscape("a"));
assertEquals("a\t", RegularEscapeUtil.basicEscape("a\t"));
assertEquals("a\\", RegularEscapeUtil.basicEscape("a\\"));
assertEquals("a\\", RegularEscapeUtil.basicEscape("a\\\\"));
}

@Test
public void zbasicEscape() {

}
}

0 comments on commit f55029a

Please sign in to comment.