Skip to content

Commit 6686e72

Browse files
committed
Check reported security bugs in log4j-1.2-api
1 parent e2b787a commit 6686e72

File tree

13 files changed

+52
-3
lines changed

13 files changed

+52
-3
lines changed

log4j-1.2-api/src/main/java/org/apache/log4j/DefaultThrowableRenderer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.StringWriter;
2525
import java.util.ArrayList;
2626

27+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2728
import org.apache.log4j.spi.ThrowableRenderer;
2829

2930
/**
@@ -39,6 +40,10 @@ public final class DefaultThrowableRenderer implements ThrowableRenderer {
3940
* @param throwable throwable, may not be null.
4041
* @return string representation.
4142
*/
43+
@SuppressFBWarnings(
44+
value = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE",
45+
justification = "The throwable is formatted into a log file, which should be private."
46+
)
4247
public static String[] render(final Throwable throwable) {
4348
final StringWriter sw = new StringWriter();
4449
final PrintWriter pw = new PrintWriter(sw);

log4j-1.2-api/src/main/java/org/apache/log4j/FileAppender.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.InterruptedIOException;
2525
import java.io.Writer;
2626

27+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2728
import org.apache.log4j.helpers.LogLog;
2829
import org.apache.log4j.helpers.QuietWriter;
2930
import org.apache.log4j.spi.ErrorCode;
@@ -248,6 +249,10 @@ public void setFile(final String file) {
248249
* @param fileName The path to the log file.
249250
* @param append If true will append to fileName. Otherwise will truncate fileName.
250251
*/
252+
@SuppressFBWarnings(
253+
value = {"PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_OUT"},
254+
justification = "The file name comes from a configuration file."
255+
)
251256
public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException {
252257
LogLog.debug("setFile called: " + fileName + ", " + append);
253258

log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.StringTokenizer;
3131
import java.util.Vector;
3232

33+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3334
import org.apache.log4j.bridge.FilterAdapter;
3435
import org.apache.log4j.config.Log4j1Configuration;
3536
import org.apache.log4j.config.PropertiesConfiguration;
@@ -356,6 +357,10 @@ public void doConfigure(final String fileName, final LoggerRepository loggerRepo
356357
* @param fileName The configuration file
357358
* @param loggerRepository The hierarchy
358359
*/
360+
@SuppressFBWarnings(
361+
value = "PATH_TRAVERSAL_IN",
362+
justification = "The filename comes from a system property."
363+
)
359364
Configuration doConfigure(final String fileName, final LoggerRepository loggerRepository, final ClassLoader classLoader) {
360365
try (final InputStream inputStream = Files.newInputStream(Paths.get(fileName))) {
361366
return doConfigure(inputStream, loggerRepository, classLoader);

log4j-1.2-api/src/main/java/org/apache/log4j/RollingFileAppender.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.InterruptedIOException;
2222
import java.io.Writer;
2323

24+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2425
import org.apache.log4j.helpers.CountingQuietWriter;
2526
import org.apache.log4j.helpers.LogLog;
2627
import org.apache.log4j.helpers.OptionConverter;
@@ -107,6 +108,10 @@ public long getMaximumFileSize() {
107108
* created.
108109
* </p>
109110
*/
111+
@SuppressFBWarnings(
112+
value = "PATH_TRAVERSAL_IN",
113+
justification = "The filename comes from a system property."
114+
)
110115
public // synchronization not necessary since doAppend is alreasy synched
111116
void rollOver() {
112117
File target;
@@ -182,6 +187,10 @@ void rollOver() {
182187
}
183188
}
184189

190+
@SuppressFBWarnings(
191+
value = "PATH_TRAVERSAL_IN",
192+
justification = "The file name comes from a configuration file."
193+
)
185194
public synchronized void setFile(final String fileName, final boolean append, final boolean bufferedIO, final int bufferSize) throws IOException {
186195
super.setFile(fileName, append, this.bufferedIO, this.bufferSize);
187196
if (append) {

log4j-1.2-api/src/main/java/org/apache/log4j/helpers/FileWatchdog.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.File;
2020

21+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22+
2123
/**
2224
* Checks every now and then that a certain file has not changed. If it has, then call the {@link #doOnChange} method.
2325
*
@@ -45,6 +47,10 @@ public abstract class FileWatchdog extends Thread {
4547
boolean warnedAlready;
4648
boolean interrupted;
4749

50+
@SuppressFBWarnings(
51+
value = "PATH_TRAVERSAL_IN",
52+
justification = "The filename comes from a system property."
53+
)
4854
protected FileWatchdog(final String fileName) {
4955
super("FileWatchdog");
5056
this.filename = fileName;

log4j-1.2-api/src/main/java/org/apache/log4j/helpers/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Log4j 1.x compatibility layer.
1919
*/
2020
@Export
21-
@Version("2.20.1")
21+
@Version("2.20.2")
2222
package org.apache.log4j.helpers;
2323

2424
import org.osgi.annotation.bundle.Export;

log4j-1.2-api/src/main/java/org/apache/log4j/layout/Log4j1XmlLayout.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import java.util.Objects;
2424

25+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2526
import org.apache.logging.log4j.core.Layout;
2627
import org.apache.logging.log4j.core.LogEvent;
2728
import org.apache.logging.log4j.core.config.Node;
@@ -86,6 +87,10 @@ public String toSerializable(final LogEvent event) {
8687
return text.toString();
8788
}
8889

90+
@SuppressFBWarnings(
91+
value = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE",
92+
justification = "The throwable is formatted into a log file, which should be private."
93+
)
8994
private void formatTo(final LogEvent event, final StringBuilder buf) {
9095
buf.append("<log4j:event logger=\"");
9196
buf.append(Transform.escapeHtmlTags(event.getLoggerName()));

log4j-1.2-api/src/main/java/org/apache/log4j/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Log4j 1.x compatibility layer.
1919
*/
2020
@Export
21-
@Version("2.20.1")
21+
@Version("2.20.2")
2222
package org.apache.log4j;
2323

2424
import org.osgi.annotation.bundle.Export;

log4j-1.2-api/src/main/java/org/apache/log4j/xml/DOMConfigurator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import javax.xml.parsers.FactoryConfigurationError;
3333

34+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3435
import org.apache.log4j.LogManager;
3536
import org.apache.log4j.config.PropertySetter;
3637
import org.apache.log4j.helpers.OptionConverter;
@@ -70,6 +71,10 @@ public class DOMConfigurator {
7071
public static void configure(final Element element) {
7172
}
7273

74+
@SuppressFBWarnings(
75+
value = "PATH_TRAVERSAL_IN",
76+
justification = "The filename comes from a system property."
77+
)
7378
public static void configure(final String fileName) throws FactoryConfigurationError {
7479
final Path path = Paths.get(fileName);
7580
try (final InputStream inputStream = Files.newInputStream(path)) {

log4j-1.2-api/src/main/java/org/apache/log4j/xml/XmlConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javax.xml.parsers.DocumentBuilderFactory;
3030
import javax.xml.parsers.FactoryConfigurationError;
3131

32+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3233
import org.apache.log4j.Appender;
3334
import org.apache.log4j.Layout;
3435
import org.apache.log4j.Level;
@@ -131,6 +132,10 @@ public void doConfigure() throws FactoryConfigurationError {
131132
final ConfigurationSource source = getConfigurationSource();
132133
final ParseAction action = new ParseAction() {
133134
@Override
135+
@SuppressFBWarnings(
136+
value = "XXE_DOCUMENT",
137+
justification = "The `DocumentBuilder` is configured to not resolve external entities."
138+
)
134139
public Document parse(final DocumentBuilder parser) throws SAXException, IOException {
135140
@SuppressWarnings("resource")
136141
final // The ConfigurationSource and its caller manages the InputStream.

0 commit comments

Comments
 (0)