Skip to content

Commit 05779ef

Browse files
authored
Merge pull request github#5368 from joefarebrother/guava-convert-to-csv
Java: Convert existing Guava models to CSV format
2 parents efeff6f + f5e4b87 commit 05779ef

File tree

8 files changed

+438
-199
lines changed

8 files changed

+438
-199
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/** Definitions of flow steps through utility methods of `com.google.common.base`. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.ExternalFlow
5+
6+
private class GuavaBaseCsv extends SummaryModelCsv {
7+
override predicate row(string row) {
8+
row =
9+
[
10+
//"package;type;overrides;name;signature;ext;inputspec;outputspec;kind",
11+
"com.google.common.base;Strings;false;emptyToNull;(String);;Argument[0];ReturnValue;value",
12+
"com.google.common.base;Strings;false;nullToEmpty;(String);;Argument[0];ReturnValue;value",
13+
"com.google.common.base;Strings;false;padStart;(String,int,char);;Argument[0];ReturnValue;taint",
14+
"com.google.common.base;Strings;false;padEnd;(String,int,char);;Argument[0];ReturnValue;taint",
15+
"com.google.common.base;Strings;false;repeat;(String,int);;Argument[0];ReturnValue;taint",
16+
"com.google.common.base;Strings;false;lenientFormat;(String,Object[]);;Argument;ReturnValue;taint",
17+
"com.google.common.base;Joiner;false;on;(String);;Argument[0];ReturnValue;taint",
18+
"com.google.common.base;Joiner;false;skipNulls;();;Argument[-1];ReturnValue;taint",
19+
"com.google.common.base;Joiner;false;useForNull;(String);;Argument[-1];ReturnValue;taint",
20+
"com.google.common.base;Joiner;false;useForNull;(String);;Argument[0];ReturnValue;taint",
21+
"com.google.common.base;Joiner;false;withKeyValueSeparator;(String);;Argument[0];ReturnValue;taint",
22+
"com.google.common.base;Joiner;false;withKeyValueSeparator;(String);;Argument[-1];ReturnValue;taint",
23+
"com.google.common.base;Joiner;false;withKeyValueSeparator;(char);;Argument[-1];ReturnValue;taint",
24+
// Note: The signatures of some of the appendTo methods involve collection flow
25+
"com.google.common.base;Joiner;false;appendTo;;;Argument;Argument[0];taint",
26+
"com.google.common.base;Joiner;false;appendTo;;;Argument[0];ReturnValue;value",
27+
"com.google.common.base;Joiner;false;join;;;Argument;ReturnValue;taint",
28+
"com.google.common.base;Joiner$MapJoiner;false;useForNull;(String);;Argument[0];ReturnValue;taint",
29+
"com.google.common.base;Joiner$MapJoiner;false;useForNull;(String);;Argument[-1];ReturnValue;taint",
30+
"com.google.common.base;Joiner$MapJoiner;false;appendTo;;;Argument;Argument[0];taint",
31+
"com.google.common.base;Joiner$MapJoiner;false;appendTo;;;Argument[0];ReturnValue;value",
32+
"com.google.common.base;Joiner$MapJoiner;false;join;;;Argument;ReturnValue;taint",
33+
"com.google.common.base;Splitter;false;split;(CharSequence);;Argument[0];ReturnValue;taint",
34+
"com.google.common.base;Splitter;false;splitToList;(CharSequence);;Argument[0];ReturnValue;taint",
35+
"com.google.common.base;Splitter;false;splitToStream;(CharSequence);;Argument[0];ReturnValue;taint",
36+
"com.google.common.base;Splitter$MapSplitter;false;split;(CharSequence);;Argument[0];ReturnValue;taint",
37+
"com.google.common.base;Preconditions;false;checkNotNull;;;Argument[0];ReturnValue;value"
38+
]
39+
}
40+
}

java/ql/src/semmle/code/java/frameworks/guava/Guava.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import java
6-
import StringUtils
6+
import Base
77
import Collections
8-
import Preconditions
98
import IO

java/ql/src/semmle/code/java/frameworks/guava/Preconditions.qll

Lines changed: 0 additions & 23 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/guava/StringUtils.qll

Lines changed: 0 additions & 169 deletions
This file was deleted.

java/ql/test/library-tests/frameworks/guava/TestStrings.java renamed to java/ql/test/library-tests/frameworks/guava/TestBase.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
2-
import com.google.common.base.Strings;
3-
import com.google.common.base.Splitter;
4-
import com.google.common.base.Joiner;
1+
package com.google.common.base;
52

63
import java.util.Map;
74
import java.util.HashMap;
85

9-
class TestStrings {
6+
class TestBase {
107
String taint() { return "tainted"; }
118

129
void sink(Object o) {}
@@ -59,4 +56,8 @@ void test3() {
5956
m.put("k2", x);
6057
sink(safeJoiner.withKeyValueSeparator("=").join(m)); // $numTaintFlow=1
6158
}
59+
60+
void test4() {
61+
sink(Preconditions.checkNotNull(taint())); // $numTaintFlow=1
62+
}
6263
}

0 commit comments

Comments
 (0)