Skip to content

Commit 97d6295

Browse files
authored
Merge pull request #20484 from kaspersv/kaspersv/future-proof-java-discarding
Overlay: Future-proof Java config & XML discard predicates
2 parents fdb0c6e + dbb9a26 commit 97d6295

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

java/ql/lib/semmle/code/java/Overlay.qll

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ predicate isOverlay() { databaseMetadata("isOverlay", "true") }
1818
overlay[local]
1919
string getRawFile(@locatable el) {
2020
exists(@location loc, @file file |
21-
hasLocation(el, loc) and
21+
(hasLocation(el, loc) or xmllocations(el, loc)) and
2222
locations_default(loc, file, _, _, _, _) and
2323
files(file, result)
2424
)
@@ -73,40 +73,22 @@ private predicate discardReferableLocatable(@locatable el) {
7373
)
7474
}
7575

76+
/** Gets the raw file for a configLocatable. */
7677
overlay[local]
77-
private predicate baseConfigLocatable(@configLocatable l) { not isOverlay() and exists(l) }
78-
79-
overlay[local]
80-
private predicate overlayHasConfigLocatables() {
81-
isOverlay() and
82-
exists(@configLocatable el)
83-
}
84-
85-
overlay[discard_entity]
86-
private predicate discardBaseConfigLocatable(@configLocatable el) {
87-
// The properties extractor is currently not incremental, so if
88-
// the overlay contains any config locatables, the overlay should
89-
// contain a full extraction and all config locatables from base
90-
// should be discarded.
91-
baseConfigLocatable(el) and overlayHasConfigLocatables()
92-
}
93-
94-
overlay[local]
95-
private predicate baseXmlLocatable(@xmllocatable l) {
96-
not isOverlay() and not files(l, _) and not xmlNs(l, _, _, _)
78+
private string getRawFileForConfig(@configLocatable el) {
79+
exists(@location loc, @file file |
80+
configLocations(el, loc) and
81+
locations_default(loc, file, _, _, _, _) and
82+
files(file, result)
83+
)
9784
}
9885

9986
overlay[local]
100-
private predicate overlayHasXmlLocatable() {
101-
isOverlay() and
102-
exists(@xmllocatable l | not files(l, _) and not xmlNs(l, _, _, _))
87+
private string baseConfigLocatable(@configLocatable el) {
88+
not isOverlay() and result = getRawFileForConfig(el)
10389
}
10490

10591
overlay[discard_entity]
106-
private predicate discardBaseXmlLocatable(@xmllocatable el) {
107-
// The XML extractor is currently not incremental, so if
108-
// the overlay contains any XML locatables, the overlay should
109-
// contain a full extraction and all XML locatables from base
110-
// should be discarded.
111-
baseXmlLocatable(el) and overlayHasXmlLocatable()
92+
private predicate discardBaseConfigLocatable(@configLocatable el) {
93+
overlayChangedFiles(baseConfigLocatable(el))
11294
}

java/ql/lib/semmle/code/xml/XML.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module;
66

77
import semmle.files.FileSystem
88
private import codeql.xml.Xml
9+
private import semmle.code.java.Overlay
910

1011
private module Input implements InputSig<File, Location> {
1112
class XmlLocatableBase = @xmllocatable or @xmlnamespaceable;
@@ -69,3 +70,13 @@ private module Input implements InputSig<File, Location> {
6970
}
7071

7172
import Make<File, Location, Input>
73+
74+
private class DiscardableXmlAttribute extends DiscardableLocatable, @xmlattribute { }
75+
76+
private class DiscardableXmlElement extends DiscardableLocatable, @xmlelement { }
77+
78+
private class DiscardableXmlComment extends DiscardableLocatable, @xmlcomment { }
79+
80+
private class DiscardableXmlCharacters extends DiscardableLocatable, @xmlcharacters { }
81+
82+
private class DiscardableXmlDtd extends DiscardableLocatable, @xmldtd { }

0 commit comments

Comments
 (0)