Skip to content

Commit 8d3a19a

Browse files
committed
JS: Fix termination criteria
Previously it was theoretically possible to create a cycle of preferred predecessors, since badness had higher precedence than depth. We now require the preferred predecessor to have lower depth. With this criteria we can remove the arbitray cap on badness.
1 parent 0fbe530 commit 8d3a19a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

javascript/ql/lib/semmle/javascript/endpoints/EndpointNaming.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ private API::Node getPreferredPredecessor(API::Node node, string name, int badne
110110
not isPackageExport(node) and
111111
// Rank predecessors by name-badness, export-distance, and name.
112112
// Since min() can only return a single value, we need a separate min() call per column.
113-
badness = min(int b | exists(getAPredecessor(node, _, b)) | b) and
113+
badness =
114+
min(API::Node pred, int b |
115+
pred = getAPredecessor(node, _, b) and
116+
// ensure the preferred predecessor is strictly closer to a root export, even if it means accepting more badness
117+
distanceFromPackageExport(pred) < distanceFromPackageExport(node)
118+
|
119+
b
120+
) and
114121
result =
115122
min(API::Node pred, string name1 |
116123
pred = getAPredecessor(node, name1, badness)
@@ -133,7 +140,7 @@ private predicate sinkHasNameCandidate(API::Node sink, string package, string na
133140
exists(API::Node baseNode, string baseName, int baseBadness, string step, int stepBadness |
134141
sinkHasNameCandidate(baseNode, package, baseName, baseBadness) and
135142
baseNode = getPreferredPredecessor(sink, step, stepBadness) and
136-
badness = (baseBadness + stepBadness).minimum(20) and
143+
badness = baseBadness + stepBadness and
137144
name = join(baseName, step)
138145
)
139146
}

0 commit comments

Comments
 (0)