Skip to content

Commit f7a4614

Browse files
committed
Add missing tests for AntPathMatcher's protected methods; fix models accordingly
1 parent dec0123 commit f7a4614

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

java/ql/src/semmle/code/java/frameworks/spring/SpringUtil.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ private class FlowSummaries extends SummaryModelCsv {
1010
row =
1111
[
1212
"org.springframework.util;AntPathMatcher;false;combine;;;Argument[0..1];ReturnValue;taint",
13-
"org.springframework.util;AntPathMatcher;false;doMatch;;;Argument[0];MapValue of Argument[2];taint",
13+
"org.springframework.util;AntPathMatcher;false;doMatch;;;Argument[1];MapValue of Argument[3];taint",
1414
"org.springframework.util;AntPathMatcher;false;extractPathWithinPattern;;;Argument[1];ReturnValue;taint",
1515
"org.springframework.util;AntPathMatcher;false;extractUriTemplateVariables;;;Argument[1];MapValue of ReturnValue;taint",
16-
"org.springframework.util;AntPathMatcher;false;tokenizePath;;;Argument[0];ArrayValue of ReturnValue;taint",
17-
"org.springframework.util;AntPathMatcher;false;tokenizePattern;;;Argument[0];ArrayValue of ReturnValue;taint",
16+
"org.springframework.util;AntPathMatcher;false;tokenizePath;;;Argument[0];ArrayElement of ReturnValue;taint",
17+
"org.springframework.util;AntPathMatcher;false;tokenizePattern;;;Argument[0];ArrayElement of ReturnValue;taint",
1818
"org.springframework.util.AntPathMatcher;AntPathStringMatcher;false;matchStrings;;;Argument[0];MapValue of Argument[1];taint",
1919
"org.springframework.util;AutoPopulatingList;false;AutoPopulatingList;(java.util.List,org.springframework.util.AutoPopulatingList.ElementFactory);;Element of Argument[0];Element of Argument[-1];value",
2020
"org.springframework.util;AutoPopulatingList;false;AutoPopulatingList;(java.util.List,java.lang.Class);;Element of Argument[0];Element of Argument[-1];value",

java/ql/test/library-tests/frameworks/spring/util/Test.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collection;
1313
import java.util.Collections;
1414
import java.util.Enumeration;
15+
import java.util.HashMap;
1516
import java.util.Iterator;
1617
import java.util.List;
1718
import java.util.Map;
@@ -54,8 +55,37 @@ public class Test {
5455
Properties newPropertiesWithMapKey(Object element) { Properties p = new Properties(); p.put(element, null); return p; }
5556
// Object newWithMapValue(Object element) { return null; }
5657
Properties newPropertiesWithMapValue(Object element) { Properties p = new Properties(); p.put(null, element); return p; }
57-
Object source() { return null; }
58-
void sink(Object o) { }
58+
static Object source() { return null; }
59+
static void sink(Object o) { }
60+
61+
// Test AntPathMatcher's protected methods:
62+
private static class AntPathMatcherTest extends AntPathMatcher {
63+
64+
public void test() throws Exception {
65+
{
66+
// "org.springframework.util;AntPathMatcher;false;doMatch;;;Argument[1];MapValue of Argument[3];taint"
67+
Map<String, String> out = new HashMap<>();
68+
String in = (String)source();
69+
this.doMatch("somePattern", in, true, out);
70+
sink(out.get("someKey")); // $hasTaintFlow
71+
}
72+
{
73+
// "org.springframework.util;AntPathMatcher;false;tokenizePath;;;Argument[0];ArrayValue of ReturnValue;taint",
74+
String[] out = null;
75+
String in = (String)source();
76+
out = this.tokenizePath(in);
77+
sink(out[0]); // $hasTaintFlow
78+
}
79+
{
80+
// "org.springframework.util;AntPathMatcher;false;tokenizePattern;;;Argument[0];ArrayValue of ReturnValue;taint",
81+
String[] out = null;
82+
String in = (String)source();
83+
out = this.tokenizePattern(in);
84+
sink(out[0]); // $hasTaintFlow
85+
}
86+
}
87+
88+
}
5989

6090
public void test() throws Exception {
6191

0 commit comments

Comments
 (0)