Skip to content

Commit

Permalink
properly set config and metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nedjitef committed Dec 20, 2021
1 parent d34d54b commit a3efd25
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions log4j-scanner/src/main/java/de/inett/cmk/log4shell/CliCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import com.logpresso.scanner.Log4j2Scanner;
import com.logpresso.scanner.Metrics;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

public class CliCheck extends Log4j2Scanner {

Configuration config;
Metrics metrics;

public static void main(String[] args) {
System.out.println("<<<log4j_scanner>>>");
String[] n_args = prepareArguments(args);
Expand All @@ -24,13 +22,22 @@ public static void main(String[] args) {
System.exit(0);
}

/**
* This is a hack, don't change
*/
@Override
public void run(String[] args) throws Exception {
config = Configuration.parseArguments(args);
metrics = new Metrics();
Field config = Log4j2Scanner.class.getDeclaredField("config");
config.setAccessible(true);
config.set(this, Configuration.parseArguments(args));

Field metrics = Log4j2Scanner.class.getDeclaredField("metrics");
metrics.setAccessible(true);
metrics.set(this, new Metrics());

run();
}

private static String[] prepareArguments(String[] cargs) {
String[] ret;
switch (cargs.length) {
Expand Down Expand Up @@ -61,4 +68,5 @@ private static String[] prepareArguments(String[] cargs) {
}
return ret;
}

}

0 comments on commit a3efd25

Please sign in to comment.