@@ -36,42 +36,47 @@ class TypeHashtable extends Class {
36
36
TypeHashtable ( ) { this .getSourceDeclaration ( ) .hasQualifiedName ( "java.util" , "Hashtable" ) }
37
37
}
38
38
39
+ string getHostname ( Expr expr ) {
40
+ result = expr .( CompileTimeConstantExpr ) .getStringValue ( ) or
41
+ result =
42
+ expr .( VarAccess ) .getVariable ( ) .getAnAssignedValue ( ) .( CompileTimeConstantExpr ) .getStringValue ( )
43
+ }
44
+
39
45
/**
40
46
* Holds if a non-private LDAP string is concatenated from both protocol and host.
41
47
*/
42
- predicate concatInsecureLdapString ( Expr protocol , Expr host ) {
43
- protocol .( CompileTimeConstantExpr ) .getStringValue ( ) = "ldap://" and
44
- not exists ( string hostString |
45
- hostString = host .( CompileTimeConstantExpr ) .getStringValue ( ) or
46
- hostString =
47
- host .( VarAccess ) .getVariable ( ) .getAnAssignedValue ( ) .( CompileTimeConstantExpr ) .getStringValue ( )
48
- |
48
+ predicate concatInsecureLdapString ( CompileTimeConstantExpr protocol , Expr host ) {
49
+ protocol .getStringValue ( ) = "ldap://" and
50
+ not exists ( string hostString | hostString = getHostname ( host ) |
49
51
hostString .length ( ) = 0 or // Empty host is loopback address
50
52
hostString instanceof PrivateHostName
51
53
)
52
54
}
53
55
54
- /** Gets the leftmost operand in a concatenated string */
55
- Expr getLeftmostConcatOperand ( Expr expr ) {
56
- // if expr instanceof AddExpr
57
- // then result = getLeftmostConcatOperand(expr.(AddExpr).getLeftOperand())
58
- // else result = expr
59
- if expr instanceof AddExpr
60
- then
61
- result = expr .( AddExpr ) .getLeftOperand * ( ) and
62
- not result instanceof AddExpr
63
- else result = expr
64
- }
65
-
56
+ // Expr getLeftmostConcatOperand(Expr expr) {
57
+ // if expr instanceof AddExpr
58
+ // then
59
+ // result = expr.(AddExpr).getLeftOperand() and
60
+ // not result instanceof AddExpr
61
+ // else result = expr
62
+ // }
66
63
/**
67
64
* String concatenated with `InsecureLdapUrlLiteral`.
68
65
*/
69
66
class InsecureLdapUrl extends Expr {
70
67
InsecureLdapUrl ( ) {
71
68
this instanceof InsecureLdapUrlLiteral
72
69
or
73
- concatInsecureLdapString ( this .( AddExpr ) .getLeftOperand ( ) ,
74
- getLeftmostConcatOperand ( this .( AddExpr ) .getRightOperand ( ) ) )
70
+ // protocol + host + ...
71
+ exists ( AddExpr e , CompileTimeConstantExpr protocol , Expr rest , Expr host |
72
+ e = this and
73
+ protocol = e .getLeftOperand ( ) and
74
+ rest = e .getRightOperand ( ) and
75
+ if rest instanceof AddExpr then host = rest .( AddExpr ) .getLeftOperand ( ) else host = rest
76
+ |
77
+ protocol .getStringValue ( ) = "ldap://" and
78
+ concatInsecureLdapString ( protocol , host )
79
+ )
75
80
}
76
81
}
77
82
0 commit comments