Skip to content

Commit e2b787a

Browse files
committed
Remove PATH_TRAVERSAL_IN/OUT and URLCONNECTION_SSRF_FD warnings
1 parent c0fcaaa commit e2b787a

32 files changed

+165
-17
lines changed

log4j-api/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
java.management;static=true
4848
</bnd-extra-module-options>
4949

50-
<!-- FIXME: temporary -->
51-
<spotbugs.skip>true</spotbugs.skip>
5250
</properties>
5351
<dependencies>
5452
<dependency>

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/package-info.java

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

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

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.TimeUnit;
2929
import java.util.zip.Deflater;
3030

31+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3132
import org.apache.logging.log4j.core.Core;
3233
import org.apache.logging.log4j.core.appender.rolling.action.Action;
3334
import org.apache.logging.log4j.core.appender.rolling.action.CompositeAction;
@@ -411,6 +412,10 @@ private int purge(final int lowIndex, final int highIndex, final RollingFileMana
411412
* @param manager The RollingFileManager
412413
* @return true if purge was successful and rollover should be attempted.
413414
*/
415+
@SuppressFBWarnings(
416+
value = "PATH_TRAVERSAL_IN",
417+
justification = "The name of the accessed files is based on a configuration value."
418+
)
414419
private int purgeAscending(final int lowIndex, final int highIndex, final RollingFileManager manager) {
415420
final SortedMap<Integer, Path> eligibleFiles = getEligibleFiles(manager);
416421
final int maxFiles = highIndex - lowIndex + 1;
@@ -467,6 +472,10 @@ private int purgeAscending(final int lowIndex, final int highIndex, final Rollin
467472
* @param manager The RollingFileManager
468473
* @return true if purge was successful and rollover should be attempted.
469474
*/
475+
@SuppressFBWarnings(
476+
value = "PATH_TRAVERSAL_IN",
477+
justification = "The name of the accessed files is based on a configuration value."
478+
)
470479
private int purgeDescending(final int lowIndex, final int highIndex, final RollingFileManager manager) {
471480
// Retrieve the files in descending order, so the highest key will be first.
472481
final SortedMap<Integer, Path> eligibleFiles = getEligibleFiles(manager, false);
@@ -517,6 +526,10 @@ private int purgeDescending(final int lowIndex, final int highIndex, final Rolli
517526
* @throws SecurityException if an error occurs.
518527
*/
519528
@Override
529+
@SuppressFBWarnings(
530+
value = "PATH_TRAVERSAL_IN",
531+
justification = "The name of the accessed files is based on a configuration value."
532+
)
520533
public RolloverDescription rollover(final RollingFileManager manager) throws SecurityException {
521534
int fileIndex;
522535
final StringBuilder buf = new StringBuilder(255);

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.concurrent.TimeUnit;
2828
import java.util.zip.Deflater;
2929

30+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3031
import org.apache.logging.log4j.core.Core;
3132
import org.apache.logging.log4j.core.appender.rolling.action.Action;
3233
import org.apache.logging.log4j.core.appender.rolling.action.CompositeAction;
@@ -340,6 +341,10 @@ public void clearCurrentFileName() {
340341
* @throws SecurityException if an error occurs.
341342
*/
342343
@Override
344+
@SuppressFBWarnings(
345+
value = "PATH_TRAVERSAL_IN",
346+
justification = "The name of the accessed files is based on a configuration value."
347+
)
343348
public RolloverDescription rollover(final RollingFileManager manager) throws SecurityException {
344349
LOGGER.debug("Rolling " + currentFileName);
345350
if (maxFiles < 0) {

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileExtension.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020
import java.util.Objects;
2121

22+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2223
import org.apache.logging.log4j.core.appender.rolling.action.Action;
2324
import org.apache.logging.log4j.core.appender.rolling.action.CommonsCompressAction;
2425
import org.apache.logging.log4j.core.appender.rolling.action.GzCompressAction;
@@ -123,10 +124,18 @@ int length() {
123124
return extension.length();
124125
}
125126

127+
@SuppressFBWarnings(
128+
value = "PATH_TRAVERSAL_IN",
129+
justification = "The name of the accessed files is based on a configuration value."
130+
)
126131
File source(final String fileName) {
127132
return new File(fileName);
128133
}
129134

135+
@SuppressFBWarnings(
136+
value = "PATH_TRAVERSAL_IN",
137+
justification = "The name of the accessed files is based on a configuration value."
138+
)
130139
File target(final String fileName) {
131140
return new File(fileName);
132141
}

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ protected RollingFileManager(final LoggerContext loggerContext, final String fil
153153
this.directWrite = rolloverStrategy instanceof DirectFileRolloverStrategy;
154154
}
155155

156+
@SuppressFBWarnings(
157+
value = "PATH_TRAVERSAL_IN",
158+
justification = "The name of the accessed files is based on a configuration value."
159+
)
156160
public void initialize() {
157161

158162
if (!initialized) {
@@ -726,7 +730,7 @@ private static class RollingFileManagerFactory implements ManagerFactory<Rolling
726730
*/
727731
@Override
728732
@SuppressFBWarnings(
729-
value = "PATH_TRAVERSAL_IN",
733+
value = {"PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_OUT"},
730734
justification = "The destination file should be specified in the configuration file."
731735
)
732736
public RollingFileManager createManager(final String name, final FactoryData data) {

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.ByteBuffer;
2525
import java.nio.file.Paths;
2626

27+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2728
import org.apache.logging.log4j.core.Layout;
2829
import org.apache.logging.log4j.core.LoggerContext;
2930
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
@@ -150,13 +151,21 @@ protected synchronized void writeToDestination(final byte[] bytes, final int off
150151
}
151152

152153
@Override
154+
@SuppressFBWarnings(
155+
value = "PATH_TRAVERSAL_IN",
156+
justification = "The name of the accessed files is based on a configuration value."
157+
)
153158
protected void createFileAfterRollover() throws IOException {
154159
final String fileName = getFileName();
155160
final File file = new File(fileName);
156161
FileUtils.makeParentDirs(file);
157162
createFileAfterRollover(fileName);
158163
}
159164

165+
@SuppressFBWarnings(
166+
value = "PATH_TRAVERSAL_IN",
167+
justification = "The name of the accessed files is based on a configuration value."
168+
)
160169
private void createFileAfterRollover(final String fileName) throws IOException {
161170
this.randomAccessFile = new RandomAccessFile(fileName, "rw");
162171
if (isAttributeViewEnabled()) {
@@ -212,6 +221,10 @@ private static class RollingRandomAccessFileManagerFactory implements
212221
* @return a RollingFileManager.
213222
*/
214223
@Override
224+
@SuppressFBWarnings(
225+
value = "PATH_TRAVERSAL_IN",
226+
justification = "The name of the accessed files is based on a configuration value."
227+
)
215228
public RollingRandomAccessFileManager createManager(final String name, final FactoryData data) {
216229
File file = null;
217230
long size = 0;

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractPathAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Set;
3030
import java.util.concurrent.TimeUnit;
3131

32+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3233
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
3334

3435
/**
@@ -101,6 +102,10 @@ protected abstract FileVisitor<Path> createFileVisitor(final Path visitorBaseDir
101102
*
102103
* @return the base path (all lookups resolved)
103104
*/
105+
@SuppressFBWarnings(
106+
value = "PATH_TRAVERSAL_IN",
107+
justification = "The name of the accessed files is based on a configuration value."
108+
)
104109
public Path getBasePath() {
105110
return Paths.get(subst.replace(getBasePathString()));
106111
}

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.nio.file.Paths;
2626
import java.nio.file.StandardCopyOption;
2727

28+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
29+
2830
/**
2931
* File rename action.
3032
*/
@@ -103,6 +105,10 @@ public boolean isRenameEmptyFiles() {
103105
* @param renameEmptyFiles if true, rename file even if empty, otherwise delete empty files.
104106
* @return true if successfully renamed.
105107
*/
108+
@SuppressFBWarnings(
109+
value = "PATH_TRAVERSAL_IN",
110+
justification = "The name of the accessed files is based on a configuration value."
111+
)
106112
public static boolean execute(final File source, final File destination, final boolean renameEmptyFiles) {
107113
if (renameEmptyFiles || (source.length() > 0)) {
108114
final File parent = destination.getParentFile();

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Support classes for the Rolling File Appender.
1919
*/
2020
@Export
21-
@Version("2.20.1")
21+
@Version("2.20.2")
2222
package org.apache.logging.log4j.core.appender.rolling.action;
2323

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

0 commit comments

Comments
 (0)