Skip to content

Commit 4c270fc

Browse files
committed
Add generalized identifier resolution for AndroidManifest
Since more than one attribute can hold an identifier, refactor identifier resolution into a separate method.
1 parent cf3e5a0 commit 4c270fc

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,30 @@ class AndroidComponentXmlElement extends XmlElement {
261261
)
262262
}
263263

264+
/**
265+
* Gets the value of an identifier attribute, and tries to resolve it into a fully qualified identifier.
266+
*/
267+
string getResolvedIdentifier(AndroidIdentifierXmlAttribute identifier) {
268+
exists(string name | name = identifier.getValue() |
269+
if name.matches(".%")
270+
then
271+
result =
272+
this.getParent()
273+
.(XmlElement)
274+
.getParent()
275+
.(AndroidManifestXmlElement)
276+
.getPackageAttributeValue() + name
277+
else result = name
278+
)
279+
}
280+
264281
/**
265282
* Gets the resolved value of the `android:name` attribute of this component element.
266283
*/
267284
string getResolvedComponentName() {
268-
if this.getComponentName().matches(".%")
269-
then
270-
result =
271-
this.getParent()
272-
.(XmlElement)
273-
.getParent()
274-
.(AndroidManifestXmlElement)
275-
.getPackageAttributeValue() + this.getComponentName()
276-
else result = this.getComponentName()
285+
exists(AndroidXmlAttribute attr | attr = this.getAnAttribute() and attr.getName() = "name" |
286+
result = getResolvedIdentifier(attr)
287+
)
277288
}
278289

279290
/**

0 commit comments

Comments
 (0)