Skip to content

Commit c80a1da

Browse files
Don't consider copyOf() and clone() in ArrayUpdate
1 parent fbac589 commit c80a1da

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

java/ql/src/experimental/semmle/code/java/security/StaticInitializationVectorQuery.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ private class ArrayUpdate extends Expr {
5050
ma.getArgument(2) = array
5151
)
5252
or
53-
exists(StaticMethodAccess ma |
54-
ma.getMethod().hasQualifiedName("java.util", "Arrays", ["copyOf", "copyOfRange"]) and
55-
ma = this and
56-
ma = array
57-
)
58-
or
5953
exists(MethodAccess ma, Method m |
6054
m = ma.getMethod() and
6155
ma = this and
@@ -66,10 +60,6 @@ private class ArrayUpdate extends Expr {
6660
m.hasQualifiedName("java.security", "SecureRandom", "nextBytes") or
6761
m.hasQualifiedName("java.util", "Random", "nextBytes")
6862
)
69-
or
70-
exists(MethodAccess ma, Method m | m = ma.getMethod() |
71-
m.getDeclaringType().hasName("byte[]") and m.hasName("clone") and ma = this and ma = array
72-
)
7363
}
7464

7565
/** Returns the updated array. */

java/ql/test/experimental/query-tests/security/CWE-1204/StaticInitializationVector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public byte[] encryptWithRandomIvWithArraysCopy(byte[] key, byte[] plaintext) th
153153
byte[] randomBytes = new byte[16];
154154
SecureRandom.getInstanceStrong().nextBytes(randomBytes);
155155

156-
byte[] iv = Arrays.copyOf(randomBytes, 16);
156+
byte[] iv = new byte[16];
157+
iv = Arrays.copyOf(randomBytes, 16);
157158

158159
GCMParameterSpec ivSpec = new GCMParameterSpec(128, iv);
159160
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");

0 commit comments

Comments
 (0)