Skip to content

Commit 76e740b

Browse files
committed
Java: Clean up some instances of getQualifiedName.
1 parent 5eaaf02 commit 76e740b

File tree

10 files changed

+31
-38
lines changed

10 files changed

+31
-38
lines changed

java/ql/lib/semmle/code/java/dataflow/FlowSources.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class EnvReadMethod extends Method {
301301

302302
/** The type `java.net.InetAddress`. */
303303
class TypeInetAddr extends RefType {
304-
TypeInetAddr() { this.getQualifiedName() = "java.net.InetAddress" }
304+
TypeInetAddr() { this.hasQualifiedName("java.net", "InetAddress") }
305305
}
306306

307307
/** A reverse DNS method. */

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ import java
66
private import semmle.code.java.dataflow.FlowSteps
77

88
class ApacheHttpGetParams extends Method {
9-
ApacheHttpGetParams() {
10-
this.getDeclaringType().getQualifiedName() = "org.apache.http.HttpMessage" and
11-
this.getName() = "getParams"
12-
}
9+
ApacheHttpGetParams() { this.hasQualifiedName("org.apache.http", "HttpMessage", "getParams") }
1310
}
1411

1512
class ApacheHttpEntityGetContent extends Method {
1613
ApacheHttpEntityGetContent() {
17-
this.getDeclaringType().getQualifiedName() = "org.apache.http.HttpEntity" and
18-
this.getName() = "getContent"
14+
this.hasQualifiedName("org.apache.http", "HttpEntity", "getContent")
1915
}
2016
}
2117

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import semmle.code.java.Type
44

55
class JaxbElement extends Class {
66
JaxbElement() {
7-
this.getAnAncestor().getQualifiedName() = "javax.xml.bind.JAXBElement" or
7+
this.getAnAncestor().hasQualifiedName("javax.xml.bind", "JAXBElement") or
88
this.getAnAnnotation().getType().getName() = "XmlRootElement"
99
}
1010
}
1111

1212
class JaxbMarshalMethod extends Method {
1313
JaxbMarshalMethod() {
14-
this.getDeclaringType().getQualifiedName() = "javax.xml.bind.Marshaller" and
14+
this.getDeclaringType().hasQualifiedName("javax.xml.bind", "Marshaller") and
1515
this.getName() = "marshal"
1616
}
1717
}

java/ql/lib/semmle/code/java/security/Encryption.qll

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ abstract class JavaxCryptoAlgoSpec extends CryptoAlgoSpec { }
284284
class JavaxCryptoCipher extends JavaxCryptoAlgoSpec {
285285
JavaxCryptoCipher() {
286286
exists(Method m | m.getAReference() = this |
287-
m.getDeclaringType().getQualifiedName() = "javax.crypto.Cipher" and
288-
m.getName() = "getInstance"
287+
m.hasQualifiedName("javax.crypto", "Cipher", "getInstance")
289288
)
290289
}
291290

@@ -295,7 +294,7 @@ class JavaxCryptoCipher extends JavaxCryptoAlgoSpec {
295294
class JavaxCryptoSecretKey extends JavaxCryptoAlgoSpec {
296295
JavaxCryptoSecretKey() {
297296
exists(Constructor c | c.getAReference() = this |
298-
c.getDeclaringType().getQualifiedName() = "javax.crypto.spec.SecretKeySpec"
297+
c.getDeclaringType().hasQualifiedName("javax.crypto.spec", "SecretKeySpec")
299298
)
300299
}
301300

@@ -320,8 +319,7 @@ class JavaxCryptoKeyGenerator extends JavaxCryptoAlgoSpec {
320319
class JavaxCryptoKeyAgreement extends JavaxCryptoAlgoSpec {
321320
JavaxCryptoKeyAgreement() {
322321
exists(Method m | m.getAReference() = this |
323-
m.getDeclaringType().getQualifiedName() = "javax.crypto.KeyAgreement" and
324-
m.getName() = "getInstance"
322+
m.hasQualifiedName("javax.crypto", "KeyAgreement", "getInstance")
325323
)
326324
}
327325

@@ -331,8 +329,7 @@ class JavaxCryptoKeyAgreement extends JavaxCryptoAlgoSpec {
331329
class JavaxCryptoKeyFactory extends JavaxCryptoAlgoSpec {
332330
JavaxCryptoKeyFactory() {
333331
exists(Method m | m.getAReference() = this |
334-
m.getDeclaringType().getQualifiedName() = "javax.crypto.SecretKeyFactory" and
335-
m.getName() = "getInstance"
332+
m.hasQualifiedName("javax.crypto", "SecretKeyFactory", "getInstance")
336333
)
337334
}
338335

@@ -348,8 +345,7 @@ class JavaSecurityMessageDigest extends JavaSecurityAlgoSpec {
348345
)
349346
or
350347
exists(Method m | m.getAReference() = this |
351-
m.getDeclaringType().hasQualifiedName("java.security", "MessageDigest") and
352-
m.getName() = "getInstance"
348+
m.hasQualifiedName("java.security", "MessageDigest", "getInstance")
353349
)
354350
}
355351

@@ -359,7 +355,7 @@ class JavaSecurityMessageDigest extends JavaSecurityAlgoSpec {
359355
class JavaSecuritySignature extends JavaSecurityAlgoSpec {
360356
JavaSecuritySignature() {
361357
exists(Constructor c | c.getAReference() = this |
362-
c.getDeclaringType().getQualifiedName() = "java.security.Signature"
358+
c.getDeclaringType().hasQualifiedName("java.security", "Signature")
363359
)
364360
}
365361

java/ql/lib/semmle/code/java/security/XSS.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ class XssVulnerableWriterSource extends MethodCall {
9797
this.getMethod() instanceof ServletResponseGetOutputStreamMethod
9898
or
9999
exists(Method m | m = this.getMethod() |
100-
m.getDeclaringType().getQualifiedName() = "javax.servlet.jsp.JspContext" and
101-
m.getName() = "getOut"
100+
m.hasQualifiedName("javax.servlet.jsp", "JspContext", "getOut")
102101
)
103102
or
104103
this.getMethod() instanceof FacesGetResponseWriterMethod

java/ql/src/Likely Bugs/Concurrency/WaitOutsideLoop.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import java
1616
class WaitMethod extends Method {
1717
WaitMethod() {
1818
this.getName() = "wait" and
19-
this.getDeclaringType().getQualifiedName() = "java.lang.Object"
19+
this.getDeclaringType() instanceof TypeObject
2020
}
2121
}
2222

java/ql/src/Security/CWE/CWE-319/UseSSLSocketFactories.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ import semmle.code.java.security.Encryption
1616

1717
class NetworkClass extends Class {
1818
NetworkClass() {
19-
this.getAnAncestor().getQualifiedName().matches("java.rmi.%") or
20-
this.getAnAncestor().getQualifiedName().matches("java.net.%") or
21-
this.getAnAncestor().getQualifiedName().matches("javax.net.%")
19+
this.getAnAncestor()
20+
.getPackage()
21+
.getName()
22+
.regexpMatch("(java\\.net|java\\.rmi|javax\\.net)(\\..*)?")
2223
}
2324
}
2425

2526
class SocketFactoryType extends RefType {
2627
SocketFactoryType() {
27-
this.getQualifiedName() = "java.rmi.server.RMIServerSocketFactory" or
28-
this.getQualifiedName() = "java.rmi.server.RMIClientSocketFactory" or
29-
this.getQualifiedName() = "javax.net.SocketFactory" or
30-
this.getQualifiedName() = "java.net.SocketImplFactory"
28+
this.hasQualifiedName("java.rmi.server", "RMIServerSocketFactory") or
29+
this.hasQualifiedName("java.rmi.server", "RMIClientSocketFactory") or
30+
this.hasQualifiedName("javax.net", "SocketFactory") or
31+
this.hasQualifiedName("java.net", "SocketImplFactory")
3132
}
3233
}
3334

3435
/** Holds if the method `m` has a factory parameter at location `p`. */
35-
cached
36+
pragma[nomagic]
3637
predicate usesFactory(Method m, int p) {
3738
m.getParameter(p).getType().(RefType).getAnAncestor() instanceof SocketFactoryType
3839
}

java/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.ql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
import java
1515

16-
predicate dangerousMethod(string descriptor) { descriptor = "java.lang.Thread.stop" }
16+
predicate dangerousMethod(string pack, string type, string name) {
17+
pack = "java.lang" and type = "Thread" and name = "stop"
18+
}
1719

18-
from MethodCall call, Method target, string descriptor
20+
from MethodCall call, Method target, string pack, string type, string name
1921
where
2022
call.getCallee() = target and
21-
descriptor = target.getDeclaringType().getQualifiedName() + "." + target.getName() and
22-
dangerousMethod(descriptor)
23-
select call, "Call to " + descriptor + " is potentially dangerous."
23+
target.hasQualifiedName(pack, type, name) and
24+
dangerousMethod(pack, type, name)
25+
select call, "Call to " + pack + "." + type + "." + name + " is potentially dangerous."

java/ql/src/experimental/Security/CWE/CWE-078/CommandInjectionRuntimeExec.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ArrayInitAtNonZeroIndex extends DataFlow::Node {
7272
class StreamConcatAtNonZeroIndex extends DataFlow::Node {
7373
StreamConcatAtNonZeroIndex() {
7474
exists(MethodCall call, int index |
75-
call.getMethod().getQualifiedName() = "java.util.stream.Stream.concat" and
75+
call.getMethod().hasQualifiedName("java.util.stream", "Stream", "concat") and
7676
call.getArgument(index) = this.asExpr() and
7777
index != 0
7878
)

java/ql/src/experimental/Security/CWE/CWE-939/IncorrectURLVerification.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class HostVerificationMethodCall extends MethodCall {
7272
exists(MethodCall ma, Method m, Field f |
7373
this.getArgument(0) = ma and
7474
ma.getMethod() = m and
75-
m.hasName("getString") and
76-
m.getDeclaringType().getQualifiedName() = "android.content.res.Resources" and
75+
m.hasQualifiedName("android.content.res", "Resources", "getString") and
7776
ma.getArgument(0).(FieldRead).getField() = f and
7877
f.getDeclaringType() instanceof AndroidRString
7978
) //Check resource properties in /res/values/strings.xml in Android mobile applications using res.getString(R.string.key)

0 commit comments

Comments
 (0)