Skip to content

Commit a77a6ec

Browse files
authored
Merge pull request github#7684 from erik-krogh/patches
small refactorizations across CodeQL
2 parents 9d89cac + a235f8f commit a77a6ec

File tree

32 files changed

+236
-243
lines changed

32 files changed

+236
-243
lines changed

cpp/ql/lib/semmle/code/cpp/commons/Printf.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ class FormatLiteral extends Literal {
11221122
* conversion specifier of this format string; has no result if this cannot
11231123
* be determined.
11241124
*/
1125-
int getMaxConvertedLength(int n) { result = max(getMaxConvertedLength(n, _)) }
1125+
int getMaxConvertedLength(int n) { result = max(this.getMaxConvertedLength(n, _)) }
11261126

11271127
/**
11281128
* Gets the maximum length of the string that can be produced by the nth
@@ -1353,7 +1353,7 @@ class FormatLiteral extends Literal {
13531353
* determining whether a buffer overflow is caused by long float to string
13541354
* conversions.
13551355
*/
1356-
int getMaxConvertedLengthLimited(int n) { result = max(getMaxConvertedLengthLimited(n, _)) }
1356+
int getMaxConvertedLengthLimited(int n) { result = max(this.getMaxConvertedLengthLimited(n, _)) }
13571357

13581358
/**
13591359
* Gets the maximum length of the string that can be produced by the nth

cpp/ql/lib/semmle/code/cpp/security/BufferWrite.qll

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ abstract class BufferWrite extends Expr {
7676
* can be found), specifying the reason for the estimation.
7777
*/
7878
int getMaxData(BufferWriteEstimationReason reason) {
79-
reason instanceof UnspecifiedEstimateReason and result = getMaxData()
79+
reason instanceof UnspecifiedEstimateReason and result = this.getMaxData()
8080
}
8181

8282
/**
@@ -85,7 +85,7 @@ abstract class BufferWrite extends Expr {
8585
* much smaller (8 bytes) than their true maximum length. This can be
8686
* helpful in determining the cause of a buffer overflow issue.
8787
*/
88-
int getMaxDataLimited() { result = getMaxData() }
88+
int getMaxDataLimited() { result = this.getMaxData() }
8989

9090
/**
9191
* Gets an upper bound to the amount of data that's being written (if one
@@ -94,7 +94,7 @@ abstract class BufferWrite extends Expr {
9494
* than their true maximum length. This can be helpful in determining the
9595
* cause of a buffer overflow issue.
9696
*/
97-
int getMaxDataLimited(BufferWriteEstimationReason reason) { result = getMaxData(reason) }
97+
int getMaxDataLimited(BufferWriteEstimationReason reason) { result = this.getMaxData(reason) }
9898

9999
/**
100100
* Gets the size of a single character of the type this
@@ -159,9 +159,11 @@ class StrCopyBW extends BufferWriteCall {
159159
this.getArgument(this.getParamSrc()).(AnalysedString).getMaxLength() * this.getCharSize()
160160
}
161161

162-
override int getMaxData(BufferWriteEstimationReason reason) { result = getMaxDataImpl(reason) }
162+
override int getMaxData(BufferWriteEstimationReason reason) {
163+
result = this.getMaxDataImpl(reason)
164+
}
163165

164-
override int getMaxData() { result = max(getMaxDataImpl(_)) }
166+
override int getMaxData() { result = max(this.getMaxDataImpl(_)) }
165167
}
166168

167169
/**
@@ -203,9 +205,11 @@ class StrCatBW extends BufferWriteCall {
203205
this.getArgument(this.getParamSrc()).(AnalysedString).getMaxLength() * this.getCharSize()
204206
}
205207

206-
override int getMaxData(BufferWriteEstimationReason reason) { result = getMaxDataImpl(reason) }
208+
override int getMaxData(BufferWriteEstimationReason reason) {
209+
result = this.getMaxDataImpl(reason)
210+
}
207211

208-
override int getMaxData() { result = max(getMaxDataImpl(_)) }
212+
override int getMaxData() { result = max(this.getMaxDataImpl(_)) }
209213
}
210214

211215
/**
@@ -269,9 +273,11 @@ class SprintfBW extends BufferWriteCall {
269273
)
270274
}
271275

272-
override int getMaxData(BufferWriteEstimationReason reason) { result = getMaxDataImpl(reason) }
276+
override int getMaxData(BufferWriteEstimationReason reason) {
277+
result = this.getMaxDataImpl(reason)
278+
}
273279

274-
override int getMaxData() { result = max(getMaxDataImpl(_)) }
280+
override int getMaxData() { result = max(this.getMaxDataImpl(_)) }
275281

276282
private int getMaxDataLimitedImpl(BufferWriteEstimationReason reason) {
277283
exists(FormatLiteral fl |
@@ -281,10 +287,10 @@ class SprintfBW extends BufferWriteCall {
281287
}
282288

283289
override int getMaxDataLimited(BufferWriteEstimationReason reason) {
284-
result = getMaxDataLimitedImpl(reason)
290+
result = this.getMaxDataLimitedImpl(reason)
285291
}
286292

287-
override int getMaxDataLimited() { result = max(getMaxDataLimitedImpl(_)) }
293+
override int getMaxDataLimited() { result = max(this.getMaxDataLimitedImpl(_)) }
288294
}
289295

290296
/**
@@ -382,9 +388,11 @@ class SnprintfBW extends BufferWriteCall {
382388
)
383389
}
384390

385-
override int getMaxData(BufferWriteEstimationReason reason) { result = getMaxDataImpl(reason) }
391+
override int getMaxData(BufferWriteEstimationReason reason) {
392+
result = this.getMaxDataImpl(reason)
393+
}
386394

387-
override int getMaxData() { result = max(getMaxDataImpl(_)) }
395+
override int getMaxData() { result = max(this.getMaxDataImpl(_)) }
388396

389397
private int getMaxDataLimitedImpl(BufferWriteEstimationReason reason) {
390398
exists(FormatLiteral fl |
@@ -394,10 +402,10 @@ class SnprintfBW extends BufferWriteCall {
394402
}
395403

396404
override int getMaxDataLimited(BufferWriteEstimationReason reason) {
397-
result = getMaxDataLimitedImpl(reason)
405+
result = this.getMaxDataLimitedImpl(reason)
398406
}
399407

400-
override int getMaxDataLimited() { result = max(getMaxDataLimitedImpl(_)) }
408+
override int getMaxDataLimited() { result = max(this.getMaxDataLimitedImpl(_)) }
401409
}
402410

403411
/**
@@ -495,9 +503,11 @@ class ScanfBW extends BufferWrite {
495503
)
496504
}
497505

498-
override int getMaxData(BufferWriteEstimationReason reason) { result = getMaxDataImpl(reason) }
506+
override int getMaxData(BufferWriteEstimationReason reason) {
507+
result = this.getMaxDataImpl(reason)
508+
}
499509

500-
override int getMaxData() { result = max(getMaxDataImpl(_)) }
510+
override int getMaxData() { result = max(this.getMaxDataImpl(_)) }
501511

502512
override string getBWDesc() {
503513
exists(FunctionCall fc |
@@ -536,7 +546,9 @@ class RealpathBW extends BufferWriteCall {
536546
this = this // Suppress a compiler warning
537547
}
538548

539-
override int getMaxData(BufferWriteEstimationReason reason) { result = getMaxDataImpl(reason) }
549+
override int getMaxData(BufferWriteEstimationReason reason) {
550+
result = this.getMaxDataImpl(reason)
551+
}
540552

541-
override int getMaxData() { result = max(getMaxDataImpl(_)) }
553+
override int getMaxData() { result = max(this.getMaxDataImpl(_)) }
542554
}

cpp/ql/src/experimental/Security/CWE/CWE-377/InsecureTemporaryFile.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ where
9292
) and
9393
exists(Variable vrtmp |
9494
vrtmp = fc.getArgument(0).(VariableAccess).getTarget() and
95-
vrtmp = fctmp.getArgument(0).(AddressOfExpr).getAddressable().(Variable) and
95+
vrtmp = fctmp.getArgument(0).(AddressOfExpr).getAddressable() and
9696
not vrtmp instanceof Field
9797
)
9898
) and

csharp/ql/test/shared/FlowSummaries.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class IncludeSummarizedCallable extends RelevantSummarizedCallable {
3838
this.getDeclaringType().hasQualifiedName(namespace, type) and
3939
result =
4040
namespace + ";" + type + ";" + this.getCallableOverride() + ";" + this.getName() + ";" + "("
41-
+ parameterQualifiedTypeNamesToString() + ")"
41+
+ this.parameterQualifiedTypeNamesToString() + ")"
4242
)
4343
}
4444
}

0 commit comments

Comments
 (0)