Skip to content

Commit 267ade6

Browse files
committed
try to only print relative paths if no full paths printed (to keep output consistent)
1 parent 9dfe722 commit 267ade6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/main/java/com/mergebase/log4j/Log4JDetector.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class Log4JDetector {
9090

9191
private static File currentDir = null;
9292
private static String currentPath = null;
93+
private static boolean printFullPaths = false;
9394

9495
public static void main(String[] args) throws IOException {
9596
currentDir = canonicalize(new File("."));
@@ -525,12 +526,14 @@ public void close() {
525526
buf.append("== 2.12.4 _SAFE_");
526527
} else {
527528
buf.append("== 2.12.3 _OKAY_");
529+
foundHits = true;
528530
}
529531
} else if (isLog4j2_17) {
530532
if (hasJdbcJndiDisabled) {
531533
buf.append(">= 2.17.1 _SAFE_");
532534
} else {
533535
buf.append("== 2.17.0 _OKAY_");
536+
foundHits = true;
534537
}
535538
} else if (isLog4j2_16) {
536539
buf.append("== 2.16.0 _OKAY_");
@@ -550,6 +553,7 @@ public void close() {
550553
buf.append("== 2.3.2 _SAFE_");
551554
} else {
552555
buf.append("== 2.3.1 _OKAY_");
556+
foundHits = true;
553557
}
554558
} else {
555559
buf.append(">= 2.0-beta9 (< 2.10.0) _VULNERABLE_");
@@ -576,10 +580,14 @@ public void close() {
576580
}
577581

578582
private static String prepareOutput(String zipPath, StringBuilder buf) {
579-
if (zipPath.startsWith(currentPath)) {
580-
zipPath = zipPath.substring(currentPath.length());
581-
if (zipPath.startsWith(File.separator)) {
582-
zipPath = zipPath.substring(1);
583+
if (!printFullPaths) {
584+
if (zipPath.startsWith(currentPath)) {
585+
zipPath = zipPath.substring(currentPath.length());
586+
if (zipPath.startsWith(File.separator)) {
587+
zipPath = zipPath.substring(1);
588+
}
589+
} else {
590+
printFullPaths = true;
583591
}
584592
}
585593
if (json) {
@@ -866,12 +874,14 @@ private static void analyze(File f) {
866874
buf.append("== 2.12.4 _SAFE_");
867875
} else {
868876
buf.append("== 2.12.3 _OKAY_");
877+
foundHits = true;
869878
}
870879
} else {
871880
if (hasJdbcJndiDisabled) {
872881
buf.append(">= 2.17.1 _SAFE_");
873882
} else {
874883
buf.append("== 2.17.0 _OKAY_");
884+
foundHits = true;
875885
}
876886
}
877887
} else if (isLog4J_2_15) {
@@ -895,6 +905,7 @@ private static void analyze(File f) {
895905
buf.append("== 2.3.2 _SAFE_");
896906
} else {
897907
buf.append("== 2.3.1 _OKAY_");
908+
foundHits = true;
898909
}
899910
} else {
900911
buf.append(">= 2.0-beta9 (< 2.10.0) _VULNERABLE_");

0 commit comments

Comments
 (0)