Skip to content
Merged
Prev Previous commit
Next Next commit
Add tests for summaries
  • Loading branch information
atorralba committed Nov 3, 2021
commit 7d88f80fb976601683981cc786c0dfb6bdaed315
17 changes: 8 additions & 9 deletions java/ql/lib/semmle/code/java/frameworks/Logging.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ private class LoggingSummaryModels extends SummaryModelCsv {
override predicate row(string row) {
row =
[
"org.apache.logging.log4j;Logger;true;entry;(Object[]);;Argument[0];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceEntry;(Message);;Argument[0];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceEntry;(String,Object[]);;Argument[0..1];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceEntry;(String,Supplier);;Argument[0..1];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceEntry;(Supplier);;Argument[0];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceEntry;(String,Supplier[]);;Argument[0..1];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceEntry;(Supplier[]);;Argument[0];ReturnValue;taint",
"org.apache.logging.log4j;Logger;true;traceExit;(EntryMessage,Object);;Argument[1];ReturnValue;value",
"org.apache.logging.log4j;Logger;true;traceExit;(Message,Object);;Argument[1];ReturnValue;value",
"org.apache.logging.log4j;Logger;true;traceExit;(Object);;Argument[0];ReturnValue;value",
"org.apache.logging.log4j;Logger;true;traceExit;(String,Object);;Argument[1];ReturnValue;value",
"org.slf4j.spi.LoggingEventBuilder;true;addArgument;;;Argument[1];Argument[-1];taint",
"org.slf4j.spi.LoggingEventBuilder;true;addArgument;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi.LoggingEventBuilder;true;addKeyValue;;;Argument[1];Argument[-1];taint",
"org.slf4j.spi.LoggingEventBuilder;true;addKeyValue;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi.LoggingEventBuilder;true;addMarker;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi.LoggingEventBuilder;true;setCause;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi;LoggingEventBuilder;true;addArgument;;;Argument[1];Argument[-1];taint",
"org.slf4j.spi;LoggingEventBuilder;true;addArgument;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi;LoggingEventBuilder;true;addKeyValue;;;Argument[1];Argument[-1];taint",
"org.slf4j.spi;LoggingEventBuilder;true;addKeyValue;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi;LoggingEventBuilder;true;addMarker;;;Argument[-1];ReturnValue;value",
"org.slf4j.spi;LoggingEventBuilder;true;setCause;;;Argument[-1];ReturnValue;value",
"java.util.logging;LogRecord;false;LogRecord;;;Argument[1];Argument[-1];taint"
]
}
Expand Down
168 changes: 168 additions & 0 deletions java/ql/test/library-tests/logging/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package generatedtest;

import java.util.logging.LogRecord;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.EntryMessage;
import org.apache.logging.log4j.message.Message;
import org.slf4j.spi.LoggingEventBuilder;

// Test case generated by GenerateFlowTestCase.ql
public class Test {

Object source() {
return null;
}

void sink(Object o) {}

public void test() throws Exception {

{
// "java.util.logging;LogRecord;false;LogRecord;;;Argument[1];Argument[-1];taint"
LogRecord out = null;
String in = (String) source();
out = new LogRecord(null, in);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceEntry;(Message);;Argument[0];ReturnValue;taint"
EntryMessage out = null;
Message in = (Message) source();
Logger instance = null;
out = instance.traceEntry(in);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceEntry;(String,Object[]);;Argument[0..1];ReturnValue;taint"
EntryMessage out = null;
Object[] in = (Object[]) source();
Logger instance = null;
out = instance.traceEntry((String) null, in);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceEntry;(String,Object[]);;Argument[0..1];ReturnValue;taint"
EntryMessage out = null;
String in = (String) source();
Logger instance = null;
out = instance.traceEntry(in, (Object[]) null);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceEntry;(String,Supplier[]);;Argument[0..1];ReturnValue;taint"
EntryMessage out = null;
String in = (String) source();
Logger instance = null;
out = instance.traceEntry(in, (org.apache.logging.log4j.util.Supplier[]) null);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceEntry;(String,Supplier[]);;Argument[0..1];ReturnValue;taint"
EntryMessage out = null;
org.apache.logging.log4j.util.Supplier[] in =
(org.apache.logging.log4j.util.Supplier[]) source();
Logger instance = null;
out = instance.traceEntry((String) null, in);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceEntry;(Supplier[]);;Argument[0];ReturnValue;taint"
EntryMessage out = null;
org.apache.logging.log4j.util.Supplier[] in =
(org.apache.logging.log4j.util.Supplier[]) source();
Logger instance = null;
out = instance.traceEntry(in);
sink(out); // $ hasTaintFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceExit;(EntryMessage,Object);;Argument[1];ReturnValue;value"
Object out = null;
Object in = (Object) source();
Logger instance = null;
out = instance.traceExit((EntryMessage) null, in);
sink(out); // $ hasValueFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceExit;(Message,Object);;Argument[1];ReturnValue;value"
Object out = null;
Object in = (Object) source();
Logger instance = null;
out = instance.traceExit((Message) null, in);
sink(out); // $ hasValueFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceExit;(Object);;Argument[0];ReturnValue;value"
Object out = null;
Object in = (Object) source();
Logger instance = null;
out = instance.traceExit(in);
sink(out); // $ hasValueFlow
}
{
// "org.apache.logging.log4j;Logger;true;traceExit;(String,Object);;Argument[1];ReturnValue;value"
Object out = null;
Object in = (Object) source();
Logger instance = null;
out = instance.traceExit((String) null, in);
sink(out); // $ hasValueFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addArgument;;;Argument[-1];ReturnValue;value"
LoggingEventBuilder out = null;
LoggingEventBuilder in = (LoggingEventBuilder) source();
out = in.addArgument((Object) null);
sink(out); // $ hasValueFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addArgument;;;Argument[-1];ReturnValue;value"
LoggingEventBuilder out = null;
LoggingEventBuilder in = (LoggingEventBuilder) source();
out = in.addArgument((java.util.function.Supplier) null);
sink(out); // $ hasValueFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addKeyValue;;;Argument[-1];ReturnValue;value"
LoggingEventBuilder out = null;
LoggingEventBuilder in = (LoggingEventBuilder) source();
out = in.addKeyValue((String) null, (Object) null);
sink(out); // $ hasValueFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addKeyValue;;;Argument[-1];ReturnValue;value"
LoggingEventBuilder out = null;
LoggingEventBuilder in = (LoggingEventBuilder) source();
out = in.addKeyValue((String) null, (java.util.function.Supplier) null);
sink(out); // $ hasValueFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addKeyValue;;;Argument[1];Argument[-1];taint"
LoggingEventBuilder out = null;
Object in = (Object) source();
out.addKeyValue((String) null, in);
sink(out); // $ hasTaintFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addKeyValue;;;Argument[1];Argument[-1];taint"
LoggingEventBuilder out = null;
java.util.function.Supplier in = (java.util.function.Supplier) source();
out.addKeyValue((String) null, in);
sink(out); // $ hasTaintFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;addMarker;;;Argument[-1];ReturnValue;value"
LoggingEventBuilder out = null;
LoggingEventBuilder in = (LoggingEventBuilder) source();
out = in.addMarker(null);
sink(out); // $ hasValueFlow
}
{
// "org.slf4j.spi;LoggingEventBuilder;true;setCause;;;Argument[-1];ReturnValue;value"
LoggingEventBuilder out = null;
LoggingEventBuilder in = (LoggingEventBuilder) source();
out = in.setCause(null);
sink(out); // $ hasValueFlow
}

}

}
1 change: 1 addition & 0 deletions java/ql/test/library-tests/logging/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args -cp ${testdir}/../../stubs/apache-log4j-2.14.1:${testdir}/../../stubs/slf4j-2.0.0
Empty file.
2 changes: 2 additions & 0 deletions java/ql/test/library-tests/logging/test.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import java
import TestUtilities.InlineFlowTest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading