Skip to content

Commit 80cbddf

Browse files
authored
Merge pull request #9817 from smowton/smowton/feature/model-java-util-properties
Java: Model `java.util.Properties.getProperty`
2 parents 9e2e32f + f9da4a0 commit 80cbddf

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added data-flow models for `java.util.Properites`. Additional results may be found where relevant data is stored in and then retrieved from a `Properties` instance.

java/ql/lib/semmle/code/java/dataflow/internal/ContainerFlow.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ private class ContainerFlowSummaries extends SummaryModelCsv {
241241
"java.util;NavigableSet;true;pollLast;();;Argument[-1].Element;ReturnValue;value;manual",
242242
"java.util;NavigableSet;true;subSet;(Object,boolean,Object,boolean);;Argument[-1].Element;ReturnValue.Element;value;manual",
243243
"java.util;NavigableSet;true;tailSet;(Object,boolean);;Argument[-1].Element;ReturnValue.Element;value;manual",
244+
"java.util;Properties;true;getProperty;(String);;Argument[-1].MapValue;ReturnValue;value;manual",
245+
"java.util;Properties;true;getProperty;(String,String);;Argument[-1].MapValue;ReturnValue;value;manual",
246+
"java.util;Properties;true;getProperty;(String,String);;Argument[1];ReturnValue;value;manual",
244247
"java.util;Scanner;true;next;(Pattern);;Argument[-1];ReturnValue;taint;manual",
245248
"java.util;Scanner;true;next;(String);;Argument[-1];ReturnValue;taint;manual",
246249
"java.util;SortedMap;true;headMap;(Object);;Argument[-1].MapKey;ReturnValue.MapKey;value;manual",

java/ql/lib/semmle/code/java/frameworks/Properties.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ class TypeProperty extends Class {
1010
}
1111

1212
/** The `getProperty` method of the class `java.util.Properties`. */
13-
class PropertiesGetPropertyMethod extends ValuePreservingMethod {
13+
class PropertiesGetPropertyMethod extends Method {
1414
PropertiesGetPropertyMethod() {
1515
getDeclaringType() instanceof TypeProperty and
1616
hasName("getProperty")
1717
}
18-
19-
override predicate returnsValue(int arg) { arg = 1 }
2018
}
2119

2220
/** The `get` method of the class `java.util.Properties`. */

java/ql/test/library-tests/dataflow/collections/Test.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@ public void run3() {
7878
sink(x18); // Flow
7979
});
8080
}
81+
82+
public void run4() {
83+
Properties p = new Properties();
84+
p.put("key", tainted);
85+
sink(p.getProperty("key")); // Flow
86+
sink(p.getProperty("key", "defaultValue")); // Flow
87+
88+
Properties clean = new Properties();
89+
sink(clean.getProperty("key", tainted)); // Flow
90+
}
8191
}

java/ql/test/library-tests/dataflow/collections/flow.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
| Test.java:49:20:49:26 | tainted | Test.java:60:12:60:14 | x14 |
1212
| Test.java:73:11:73:17 | tainted | Test.java:75:10:75:12 | x17 |
1313
| Test.java:73:11:73:17 | tainted | Test.java:78:12:78:14 | x18 |
14+
| Test.java:84:18:84:24 | tainted | Test.java:85:10:85:29 | getProperty(...) |
15+
| Test.java:84:18:84:24 | tainted | Test.java:86:10:86:45 | getProperty(...) |
16+
| Test.java:89:35:89:41 | tainted | Test.java:89:10:89:42 | getProperty(...) |

0 commit comments

Comments
 (0)