Skip to content

Commit 61b7180

Browse files
committed
Add codeql sources (6c2713d)
1 parent fb40b8a commit 61b7180

File tree

884 files changed

+68357
-13633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

884 files changed

+68357
-13633
lines changed

repo-tests/codeql.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a2371370ff8260e789342e0ac759bc67ed401702
1+
6c2713dd8bf76ae1207e3123900a04d6f89b5162

repo-tests/codeql/cpp/ql/lib/experimental/semmle/code/cpp/security/PrivateCleartextWrite.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ module PrivateCleartextWrite {
5252

5353
class WriteSink extends Sink {
5454
WriteSink() {
55-
exists(FileWrite f, BufferWrite b |
56-
this.asExpr() = f.getASource()
57-
or
58-
this.asExpr() = b.getAChild()
59-
)
55+
this.asExpr() = any(FileWrite f).getASource() or
56+
this.asExpr() = any(BufferWrite b).getAChild()
6057
}
6158
}
6259
}

repo-tests/codeql/cpp/ql/lib/experimental/semmle/code/cpp/security/PrivateData.qll

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,25 @@ import cpp
1313

1414
/** A string for `match` that identifies strings that look like they represent private data. */
1515
private string privateNames() {
16-
// Inspired by the list on https://cwe.mitre.org/data/definitions/359.html
17-
// Government identifiers, such as Social Security Numbers
18-
result = "%social%security%number%" or
19-
// Contact information, such as home addresses and telephone numbers
20-
result = "%postcode%" or
21-
result = "%zipcode%" or
22-
// result = "%telephone%" or
23-
// Geographic location - where the user is (or was)
24-
result = "%latitude%" or
25-
result = "%longitude%" or
26-
// Financial data - such as credit card numbers, salary, bank accounts, and debts
27-
result = "%creditcard%" or
28-
result = "%salary%" or
29-
result = "%bankaccount%" or
30-
// Communications - e-mail addresses, private e-mail messages, SMS text messages, chat logs, etc.
31-
// result = "%email%" or
32-
// result = "%mobile%" or
33-
result = "%employer%" or
34-
// Health - medical conditions, insurance status, prescription records
35-
result = "%medical%"
16+
result =
17+
[
18+
// Inspired by the list on https://cwe.mitre.org/data/definitions/359.html
19+
// Government identifiers, such as Social Security Numbers
20+
"%social%security%number%",
21+
// Contact information, such as home addresses and telephone numbers
22+
"%postcode%", "%zipcode%",
23+
// result = "%telephone%" or
24+
// Geographic location - where the user is (or was)
25+
"%latitude%", "%longitude%",
26+
// Financial data - such as credit card numbers, salary, bank accounts, and debts
27+
"%creditcard%", "%salary%", "%bankaccount%",
28+
// Communications - e-mail addresses, private e-mail messages, SMS text messages, chat logs, etc.
29+
// result = "%email%" or
30+
// result = "%mobile%" or
31+
"%employer%",
32+
// Health - medical conditions, insurance status, prescription records
33+
"%medical%"
34+
]
3635
}
3736

3837
/** An expression that might contain private data. */

repo-tests/codeql/cpp/ql/lib/external/ExternalArtifact.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExternalData extends @externalDataElement {
1515
* Gets the path of the file this data was loaded from, with its
1616
* extension replaced by `.ql`.
1717
*/
18-
string getQueryPath() { result = getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") }
18+
string getQueryPath() { result = this.getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") }
1919

2020
/** Gets the number of fields in this data item. */
2121
int getNumFields() { result = 1 + max(int i | externalData(this, _, i, _) | i) }
@@ -24,22 +24,22 @@ class ExternalData extends @externalDataElement {
2424
string getField(int i) { externalData(this, _, i, result) }
2525

2626
/** Gets the integer value of the `i`th field of this data item. */
27-
int getFieldAsInt(int i) { result = getField(i).toInt() }
27+
int getFieldAsInt(int i) { result = this.getField(i).toInt() }
2828

2929
/** Gets the floating-point value of the `i`th field of this data item. */
30-
float getFieldAsFloat(int i) { result = getField(i).toFloat() }
30+
float getFieldAsFloat(int i) { result = this.getField(i).toFloat() }
3131

3232
/** Gets the value of the `i`th field of this data item, interpreted as a date. */
33-
date getFieldAsDate(int i) { result = getField(i).toDate() }
33+
date getFieldAsDate(int i) { result = this.getField(i).toDate() }
3434

3535
/** Gets a textual representation of this data item. */
36-
string toString() { result = getQueryPath() + ": " + buildTupleString(0) }
36+
string toString() { result = this.getQueryPath() + ": " + this.buildTupleString(0) }
3737

3838
/** Gets a textual representation of this data item, starting with the `n`th field. */
3939
private string buildTupleString(int n) {
40-
n = getNumFields() - 1 and result = getField(n)
40+
n = this.getNumFields() - 1 and result = this.getField(n)
4141
or
42-
n < getNumFields() - 1 and result = getField(n) + "," + buildTupleString(n + 1)
42+
n < this.getNumFields() - 1 and result = this.getField(n) + "," + this.buildTupleString(n + 1)
4343
}
4444
}
4545

@@ -53,8 +53,8 @@ class DefectExternalData extends ExternalData {
5353
}
5454

5555
/** Gets the URL associated with this data item. */
56-
string getURL() { result = getField(0) }
56+
string getURL() { result = this.getField(0) }
5757

5858
/** Gets the message associated with this data item. */
59-
string getMessage() { result = getField(1) }
59+
string getMessage() { result = this.getField(1) }
6060
}

repo-tests/codeql/cpp/ql/lib/semmle/code/cpp/Class.qll

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class Class extends UserType {
237237
exists(ClassDerivation cd | cd.getBaseClass() = base |
238238
result =
239239
this.accessOfBaseMemberMulti(cd.getDerivedClass(),
240-
fieldInBase.accessInDirectDerived(cd.getASpecifier().(AccessSpecifier)))
240+
fieldInBase.accessInDirectDerived(cd.getASpecifier()))
241241
)
242242
}
243243

@@ -261,21 +261,20 @@ class Class extends UserType {
261261
* includes the case of `base` = `this`.
262262
*/
263263
AccessSpecifier accessOfBaseMember(Declaration member) {
264-
result =
265-
this.accessOfBaseMember(member.getDeclaringType(), member.getASpecifier().(AccessSpecifier))
264+
result = this.accessOfBaseMember(member.getDeclaringType(), member.getASpecifier())
266265
}
267266

268267
/**
269268
* DEPRECATED: name changed to `hasImplicitCopyConstructor` to reflect that
270269
* `= default` members are no longer included.
271270
*/
272-
deprecated predicate hasGeneratedCopyConstructor() { hasImplicitCopyConstructor() }
271+
deprecated predicate hasGeneratedCopyConstructor() { this.hasImplicitCopyConstructor() }
273272

274273
/**
275274
* DEPRECATED: name changed to `hasImplicitCopyAssignmentOperator` to
276275
* reflect that `= default` members are no longer included.
277276
*/
278-
deprecated predicate hasGeneratedCopyAssignmentOperator() { hasImplicitCopyConstructor() }
277+
deprecated predicate hasGeneratedCopyAssignmentOperator() { this.hasImplicitCopyConstructor() }
279278

280279
/**
281280
* Holds if this class, struct or union has an implicitly-declared copy
@@ -319,7 +318,7 @@ class Class extends UserType {
319318
exists(Type t | t = this.getAFieldSubobjectType().getUnspecifiedType() |
320319
// Note: Overload resolution is not implemented -- all copy
321320
// constructors are considered equal.
322-
this.cannotAccessCopyConstructorOnAny(t.(Class))
321+
this.cannotAccessCopyConstructorOnAny(t)
323322
)
324323
or
325324
// - T has direct or virtual base class that cannot be copied (has deleted,
@@ -392,7 +391,7 @@ class Class extends UserType {
392391
exists(Type t | t = this.getAFieldSubobjectType().getUnspecifiedType() |
393392
// Note: Overload resolution is not implemented -- all copy assignment
394393
// operators are considered equal.
395-
this.cannotAccessCopyAssignmentOperatorOnAny(t.(Class))
394+
this.cannotAccessCopyAssignmentOperatorOnAny(t)
396395
)
397396
or
398397
exists(Class c | c = this.getADirectOrVirtualBase() |
@@ -487,7 +486,7 @@ class Class extends UserType {
487486
exists(ClassDerivation cd |
488487
// Add the offset of the direct base class and the offset of `baseClass`
489488
// within that direct base class.
490-
cd = getADerivation() and
489+
cd = this.getADerivation() and
491490
result = cd.getBaseClass().getANonVirtualBaseClassByteOffset(baseClass) + cd.getByteOffset()
492491
)
493492
}
@@ -502,12 +501,12 @@ class Class extends UserType {
502501
*/
503502
int getABaseClassByteOffset(Class baseClass) {
504503
// Handle the non-virtual case.
505-
result = getANonVirtualBaseClassByteOffset(baseClass)
504+
result = this.getANonVirtualBaseClassByteOffset(baseClass)
506505
or
507506
exists(Class virtualBaseClass, int virtualBaseOffset, int offsetFromVirtualBase |
508507
// Look for the base class as a non-virtual base of a direct or indirect
509508
// virtual base, adding the two offsets.
510-
getVirtualBaseClassByteOffset(virtualBaseClass) = virtualBaseOffset and
509+
this.getVirtualBaseClassByteOffset(virtualBaseClass) = virtualBaseOffset and
511510
offsetFromVirtualBase = virtualBaseClass.getANonVirtualBaseClassByteOffset(baseClass) and
512511
result = virtualBaseOffset + offsetFromVirtualBase
513512
)
@@ -623,11 +622,11 @@ class Class extends UserType {
623622
* inherits one).
624623
*/
625624
predicate isPolymorphic() {
626-
exists(MemberFunction f | f.getDeclaringType() = getABaseClass*() and f.isVirtual())
625+
exists(MemberFunction f | f.getDeclaringType() = this.getABaseClass*() and f.isVirtual())
627626
}
628627

629628
override predicate involvesTemplateParameter() {
630-
getATemplateArgument().(Type).involvesTemplateParameter()
629+
this.getATemplateArgument().(Type).involvesTemplateParameter()
631630
}
632631

633632
/** Holds if this class, struct or union was declared 'final'. */
@@ -765,7 +764,7 @@ class ClassDerivation extends Locatable, @derivation {
765764
* };
766765
* ```
767766
*/
768-
Class getBaseClass() { result = getBaseType().getUnderlyingType() }
767+
Class getBaseClass() { result = this.getBaseType().getUnderlyingType() }
769768

770769
override string getAPrimaryQlClass() { result = "ClassDerivation" }
771770

@@ -818,7 +817,7 @@ class ClassDerivation extends Locatable, @derivation {
818817
predicate hasSpecifier(string s) { this.getASpecifier().hasName(s) }
819818

820819
/** Holds if the derivation is for a virtual base class. */
821-
predicate isVirtual() { hasSpecifier("virtual") }
820+
predicate isVirtual() { this.hasSpecifier("virtual") }
822821

823822
/** Gets the location of the derivation. */
824823
override Location getLocation() { derivations(underlyingElement(this), _, _, _, result) }
@@ -846,7 +845,7 @@ class ClassDerivation extends Locatable, @derivation {
846845
* ```
847846
*/
848847
class LocalClass extends Class {
849-
LocalClass() { isLocal() }
848+
LocalClass() { this.isLocal() }
850849

851850
override string getAPrimaryQlClass() { not this instanceof LocalStruct and result = "LocalClass" }
852851

@@ -989,9 +988,9 @@ class ClassTemplateSpecialization extends Class {
989988
TemplateClass getPrimaryTemplate() {
990989
// Ignoring template arguments, the primary template has the same name
991990
// as each of its specializations.
992-
result.getSimpleName() = getSimpleName() and
991+
result.getSimpleName() = this.getSimpleName() and
993992
// It is in the same namespace as its specializations.
994-
result.getNamespace() = getNamespace() and
993+
result.getNamespace() = this.getNamespace() and
995994
// It is distinguished by the fact that each of its template arguments
996995
// is a distinct template parameter.
997996
count(TemplateParameter tp | tp = result.getATemplateArgument()) =
@@ -1108,7 +1107,7 @@ deprecated class Interface extends Class {
11081107
* ```
11091108
*/
11101109
class VirtualClassDerivation extends ClassDerivation {
1111-
VirtualClassDerivation() { hasSpecifier("virtual") }
1110+
VirtualClassDerivation() { this.hasSpecifier("virtual") }
11121111

11131112
override string getAPrimaryQlClass() { result = "VirtualClassDerivation" }
11141113
}
@@ -1136,7 +1135,7 @@ class VirtualBaseClass extends Class {
11361135
VirtualClassDerivation getAVirtualDerivation() { result.getBaseClass() = this }
11371136

11381137
/** A class/struct that is derived from this one using virtual inheritance. */
1139-
Class getAVirtuallyDerivedClass() { result = getAVirtualDerivation().getDerivedClass() }
1138+
Class getAVirtuallyDerivedClass() { result = this.getAVirtualDerivation().getDerivedClass() }
11401139
}
11411140

11421141
/**
@@ -1155,7 +1154,7 @@ class ProxyClass extends UserType {
11551154
override string getAPrimaryQlClass() { result = "ProxyClass" }
11561155

11571156
/** Gets the location of the proxy class. */
1158-
override Location getLocation() { result = getTemplateParameter().getDefinitionLocation() }
1157+
override Location getLocation() { result = this.getTemplateParameter().getDefinitionLocation() }
11591158

11601159
/** Gets the template parameter for which this is the proxy class. */
11611160
TemplateParameter getTemplateParameter() {

repo-tests/codeql/cpp/ql/lib/semmle/code/cpp/Declaration.qll

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class Declaration extends Locatable, @declaration {
184184
predicate hasDefinition() { exists(this.getDefinition()) }
185185

186186
/** DEPRECATED: Use `hasDefinition` instead. */
187-
predicate isDefined() { hasDefinition() }
187+
predicate isDefined() { this.hasDefinition() }
188188

189189
/** Gets the preferred location of this declaration, if any. */
190190
override Location getLocation() { none() }
@@ -209,7 +209,7 @@ class Declaration extends Locatable, @declaration {
209209
predicate isStatic() { this.hasSpecifier("static") }
210210

211211
/** Holds if this declaration is a member of a class/struct/union. */
212-
predicate isMember() { hasDeclaringType() }
212+
predicate isMember() { this.hasDeclaringType() }
213213

214214
/** Holds if this declaration is a member of a class/struct/union. */
215215
predicate hasDeclaringType() { exists(this.getDeclaringType()) }
@@ -226,14 +226,14 @@ class Declaration extends Locatable, @declaration {
226226
* When called on a template, this will return a template parameter type for
227227
* both typed and non-typed parameters.
228228
*/
229-
final Locatable getATemplateArgument() { result = getTemplateArgument(_) }
229+
final Locatable getATemplateArgument() { result = this.getTemplateArgument(_) }
230230

231231
/**
232232
* Gets a template argument used to instantiate this declaration from a template.
233233
* When called on a template, this will return a non-typed template
234234
* parameter value.
235235
*/
236-
final Locatable getATemplateArgumentKind() { result = getTemplateArgumentKind(_) }
236+
final Locatable getATemplateArgumentKind() { result = this.getTemplateArgumentKind(_) }
237237

238238
/**
239239
* Gets the `i`th template argument used to instantiate this declaration from a
@@ -252,9 +252,9 @@ class Declaration extends Locatable, @declaration {
252252
* `getTemplateArgument(1)` return `1`.
253253
*/
254254
final Locatable getTemplateArgument(int index) {
255-
if exists(getTemplateArgumentValue(index))
256-
then result = getTemplateArgumentValue(index)
257-
else result = getTemplateArgumentType(index)
255+
if exists(this.getTemplateArgumentValue(index))
256+
then result = this.getTemplateArgumentValue(index)
257+
else result = this.getTemplateArgumentType(index)
258258
}
259259

260260
/**
@@ -275,13 +275,13 @@ class Declaration extends Locatable, @declaration {
275275
* `getTemplateArgumentKind(0)`.
276276
*/
277277
final Locatable getTemplateArgumentKind(int index) {
278-
exists(getTemplateArgumentValue(index)) and
279-
result = getTemplateArgumentType(index)
278+
exists(this.getTemplateArgumentValue(index)) and
279+
result = this.getTemplateArgumentType(index)
280280
}
281281

282282
/** Gets the number of template arguments for this declaration. */
283283
final int getNumberOfTemplateArguments() {
284-
result = count(int i | exists(getTemplateArgument(i)))
284+
result = count(int i | exists(this.getTemplateArgument(i)))
285285
}
286286

287287
private Type getTemplateArgumentType(int index) {
@@ -327,9 +327,9 @@ class DeclarationEntry extends Locatable, TDeclarationEntry {
327327
* available), or the name declared by this entry otherwise.
328328
*/
329329
string getCanonicalName() {
330-
if getDeclaration().hasDefinition()
331-
then result = getDeclaration().getDefinition().getName()
332-
else result = getName()
330+
if this.getDeclaration().hasDefinition()
331+
then result = this.getDeclaration().getDefinition().getName()
332+
else result = this.getName()
333333
}
334334

335335
/**
@@ -370,18 +370,18 @@ class DeclarationEntry extends Locatable, TDeclarationEntry {
370370
/**
371371
* Holds if this declaration entry has a specifier with the given name.
372372
*/
373-
predicate hasSpecifier(string specifier) { getASpecifier() = specifier }
373+
predicate hasSpecifier(string specifier) { this.getASpecifier() = specifier }
374374

375375
/** Holds if this declaration entry is a definition. */
376376
predicate isDefinition() { none() } // overridden in subclasses
377377

378378
override string toString() {
379-
if isDefinition()
380-
then result = "definition of " + getName()
379+
if this.isDefinition()
380+
then result = "definition of " + this.getName()
381381
else
382-
if getName() = getCanonicalName()
383-
then result = "declaration of " + getName()
384-
else result = "declaration of " + getCanonicalName() + " as " + getName()
382+
if this.getName() = this.getCanonicalName()
383+
then result = "declaration of " + this.getName()
384+
else result = "declaration of " + this.getCanonicalName() + " as " + this.getName()
385385
}
386386
}
387387

@@ -490,8 +490,7 @@ class AccessHolder extends Declaration, TAccessHolder {
490490
*/
491491
pragma[inline]
492492
predicate canAccessMember(Declaration member, Class derived) {
493-
this.couldAccessMember(member.getDeclaringType(), member.getASpecifier().(AccessSpecifier),
494-
derived)
493+
this.couldAccessMember(member.getDeclaringType(), member.getASpecifier(), derived)
495494
}
496495

497496
/**
@@ -580,7 +579,7 @@ private class DirectAccessHolder extends Element {
580579
// transitive closure with a restricted base case.
581580
this.thisCanAccessClassStep(base, derived)
582581
or
583-
exists(Class between | thisCanAccessClassTrans(base, between) |
582+
exists(Class between | this.thisCanAccessClassTrans(base, between) |
584583
isDirectPublicBaseOf(between, derived) or
585584
this.thisCanAccessClassStep(between, derived)
586585
)

0 commit comments

Comments
 (0)