@@ -22,37 +22,21 @@ class TypeHashtable extends Class {
22
22
TypeHashtable ( ) { this .getSourceDeclaration ( ) .hasQualifiedName ( "java.util" , "Hashtable" ) }
23
23
}
24
24
25
- string getHostname ( Expr expr ) {
25
+ /** Get the string value of an expression representing a hostname. */
26
+ private string getHostname ( Expr expr ) {
26
27
result = expr .( CompileTimeConstantExpr ) .getStringValue ( ) or
27
28
result =
28
29
expr .( VarAccess ) .getVariable ( ) .getAnAssignedValue ( ) .( CompileTimeConstantExpr ) .getStringValue ( )
29
30
}
30
31
31
- /**
32
- * Holds if a non-private LDAP string is concatenated from both protocol and host.
33
- */
34
- predicate concatInsecureLdapString ( CompileTimeConstantExpr protocol , Expr host ) {
35
- protocol .getStringValue ( ) = "ldap://" and
36
- not exists ( string hostString | hostString = getHostname ( host ) |
37
- hostString .length ( ) = 0 or // Empty host is loopback address
38
- hostString instanceof PrivateHostName
39
- )
40
- }
41
-
42
- // Expr getLeftmostConcatOperand(Expr expr) {
43
- // if expr instanceof AddExpr
44
- // then
45
- // result = expr.(AddExpr).getLeftOperand() and
46
- // not result instanceof AddExpr
47
- // else result = expr
48
- // }
49
32
/**
50
33
* String concatenated with `InsecureLdapUrlLiteral`.
51
34
*/
52
35
class InsecureLdapUrl extends Expr {
53
36
InsecureLdapUrl ( ) {
54
37
this instanceof InsecureLdapUrlLiteral
55
38
or
39
+ // Concatentation of insecure protcol and non-private host:
56
40
// protocol + host + ...
57
41
exists ( AddExpr e , CompileTimeConstantExpr protocol , Expr rest , Expr host |
58
42
e = this and
@@ -61,7 +45,10 @@ class InsecureLdapUrl extends Expr {
61
45
if rest instanceof AddExpr then host = rest .( AddExpr ) .getLeftOperand ( ) else host = rest
62
46
|
63
47
protocol .getStringValue ( ) = "ldap://" and
64
- concatInsecureLdapString ( protocol , host )
48
+ not exists ( string hostString | hostString = getHostname ( host ) |
49
+ hostString .length ( ) = 0 or // Empty host is loopback address
50
+ hostString instanceof PrivateHostName
51
+ )
65
52
)
66
53
}
67
54
}
0 commit comments