Skip to content

Commit 12f2eb5

Browse files
authored
fix(rules): CODE-9032 (#3683)
* fix for CODE-9032 * add test
1 parent 54c51a3 commit 12f2eb5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

java/lang/security/audit/formatted-sql-string.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,23 @@ public void get(HttpServletRequest req) {
152152
// ruleid: formatted-sql-string
153153
ResultSet rs = statement.executeQuery();
154154
}
155+
}
156+
157+
public class SqlExampleNonStringBuilderConstructor{
158+
159+
public Retry<ResultSet> getRetry(final String mainQuery, final Connection connection) {
160+
// not a StringBuilder
161+
return new Retry<>(
162+
// also not a StringBuilder
163+
new Callable<ResultSet>() {
164+
public ResultSet call() throws SQLException {
165+
PreparedStatement statement = connection.prepareStatement(
166+
mainQuery, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
167+
statement.setFetchSize(Integer.MIN_VALUE);
168+
// ok: formatted-sql-string
169+
return statement.executeQuery ();
170+
}
171+
},
172+
Retry.RETRY_FOREVER);
173+
}
155174
}

java/lang/security/audit/formatted-sql-string.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ rules:
5252
- pattern-either:
5353
- pattern: $X + $INPUT
5454
- pattern: $X += $INPUT
55-
- pattern: $STRB.append($INPUT)
5655
- pattern: String.format(..., $INPUT, ...)
5756
- pattern: String.join(..., $INPUT, ...)
5857
- pattern: (String $STR).concat($INPUT)
5958
- pattern: $INPUT.concat(...)
60-
- pattern: new $STRB(..., $INPUT, ...)
59+
- patterns:
60+
- pattern-either:
61+
- pattern: $STRB.append($INPUT)
62+
- pattern: new $STRB(..., $INPUT, ...)
63+
- metavariable-type:
64+
metavariable: $STRB
65+
type: StringBuilder
6166
label: CONCAT
6267
requires: INPUT
6368
pattern-propagators:

0 commit comments

Comments
 (0)