Skip to content

Commit 7f68b07

Browse files
committed
Merge branch 'main' into regexpParse
2 parents 044fbc0 + 19fac60 commit 7f68b07

File tree

268 files changed

+4216
-1625
lines changed

Some content is hidden

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

268 files changed

+4216
-1625
lines changed

config/identical-files.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,12 @@
409409
"java/ql/src/Metrics/Files/CommentedOutCodeReferences.qhelp",
410410
"javascript/ql/src/Comments/CommentedOutCodeReferences.qhelp",
411411
"python/ql/src/Lexical/CommentedOutCodeReferences.qhelp"
412+
],
413+
"IDE Contextual Queries": [
414+
"cpp/ql/src/IDEContextual.qll",
415+
"csharp/ql/src/IDEContextual.qll",
416+
"java/ql/src/IDEContextual.qll",
417+
"javascript/ql/src/IDEContextual.qll",
418+
"python/ql/src/analysis/IDEContextual.qll"
412419
]
413420
}

cpp/ql/src/IDEContextual.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Provides shared predicates related to contextual queries in the code viewer.
3+
*/
4+
5+
import semmle.files.FileSystem
6+
7+
/**
8+
* Returns the `File` matching the given source file name as encoded by the VS
9+
* Code extension.
10+
*/
11+
cached
12+
File getFileBySourceArchiveName(string name) {
13+
// The name provided for a file in the source archive by the VS Code extension
14+
// has some differences from the absolute path in the database:
15+
// 1. colons are replaced by underscores
16+
// 2. there's a leading slash, even for Windows paths: "C:/foo/bar" ->
17+
// "/C_/foo/bar"
18+
// 3. double slashes in UNC prefixes are replaced with a single slash
19+
// We can handle 2 and 3 together by unconditionally adding a leading slash
20+
// before replacing double slashes.
21+
name = ("/" + result.getAbsolutePath().replaceAll(":", "_")).replaceAll("//", "/")
22+
}

cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ class SafeTimeGatheringFunction extends Function {
5050
class TimeConversionFunction extends Function {
5151
TimeConversionFunction() {
5252
this.getQualifiedName() =
53-
["FileTimeToSystemTime", "SystemTimeToFileTime", "SystemTimeToTzSpecificLocalTime",
54-
"SystemTimeToTzSpecificLocalTimeEx", "TzSpecificLocalTimeToSystemTime",
55-
"TzSpecificLocalTimeToSystemTimeEx", "RtlLocalTimeToSystemTime",
56-
"RtlTimeToSecondsSince1970", "_mkgmtime"]
53+
[
54+
"FileTimeToSystemTime", "SystemTimeToFileTime", "SystemTimeToTzSpecificLocalTime",
55+
"SystemTimeToTzSpecificLocalTimeEx", "TzSpecificLocalTimeToSystemTime",
56+
"TzSpecificLocalTimeToSystemTimeEx", "RtlLocalTimeToSystemTime",
57+
"RtlTimeToSecondsSince1970", "_mkgmtime"
58+
]
5759
}
5860
}
5961

cpp/ql/src/definitions.qll

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import cpp
7+
import IDEContextual
78

89
/**
910
* Any element that might be the source or target of a jump-to-definition
@@ -207,11 +208,3 @@ Top definitionOf(Top e, string kind) {
207208
// later on.
208209
strictcount(result.getLocation()) < 10
209210
}
210-
211-
/**
212-
* Returns an appropriately encoded version of a filename `name`
213-
* passed by the VS Code extension in order to coincide with the
214-
* output of `.getFile()` on locatable entities.
215-
*/
216-
cached
217-
File getEncodedFile(string name) { result.getAbsolutePath().replaceAll(":", "_") = name }

cpp/ql/src/experimental/semmle/code/cpp/security/PrivateCleartextWrite.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import semmle.code.cpp.dataflow.TaintTracking
77
import experimental.semmle.code.cpp.security.PrivateData
88
import semmle.code.cpp.security.FileWrite
99
import semmle.code.cpp.security.BufferWrite
10-
import semmle.code.cpp.dataflow.TaintTracking
1110

1211
module PrivateCleartextWrite {
1312
/**

cpp/ql/src/localDefinitions.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ import definitions
1212
external string selectedSourceFile();
1313

1414
from Top e, Top def, string kind
15-
where def = definitionOf(e, kind) and e.getFile() = getEncodedFile(selectedSourceFile())
15+
where def = definitionOf(e, kind) and e.getFile() = getFileBySourceArchiveName(selectedSourceFile())
1616
select e, def, kind

cpp/ql/src/localReferences.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ import definitions
1212
external string selectedSourceFile();
1313

1414
from Top e, Top def, string kind
15-
where def = definitionOf(e, kind) and def.getFile() = getEncodedFile(selectedSourceFile())
15+
where
16+
def = definitionOf(e, kind) and def.getFile() = getFileBySourceArchiveName(selectedSourceFile())
1617
select e, def, kind

cpp/ql/src/printAst.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class Cfg extends PrintASTConfiguration {
2222
* Print All functions from the selected file.
2323
*/
2424
override predicate shouldPrintFunction(Function func) {
25-
func.getFile() = getEncodedFile(selectedSourceFile())
25+
func.getFile() = getFileBySourceArchiveName(selectedSourceFile())
2626
}
2727
}

cpp/ql/src/semmle/code/cpp/commons/Strcat.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import cpp
99
class StrcatFunction extends Function {
1010
StrcatFunction() {
1111
getName() =
12-
["strcat", // strcat(dst, src)
13-
"strncat", // strncat(dst, src, max_amount)
14-
"wcscat", // wcscat(dst, src)
15-
"_mbscat", // _mbscat(dst, src)
16-
"wcsncat", // wcsncat(dst, src, max_amount)
17-
"_mbsncat", // _mbsncat(dst, src, max_amount)
18-
"_mbsncat_l"] // _mbsncat_l(dst, src, max_amount, locale)
12+
[
13+
"strcat", // strcat(dst, src)
14+
"strncat", // strncat(dst, src, max_amount)
15+
"wcscat", // wcscat(dst, src)
16+
"_mbscat", // _mbscat(dst, src)
17+
"wcsncat", // wcsncat(dst, src, max_amount)
18+
"_mbsncat", // _mbsncat(dst, src, max_amount)
19+
"_mbsncat_l" // _mbsncat_l(dst, src, max_amount, locale)
20+
]
1921
}
2022
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ private predicate exprToExprStep_nocfg(Expr fromExpr, Expr toExpr) {
677677
exists(DataFlowFunction f, FunctionInput inModel, FunctionOutput outModel |
678678
f.hasDataFlow(inModel, outModel) and
679679
(
680+
exists(int iIn |
681+
inModel.isParameterDeref(iIn) and
682+
call.passesByReference(iIn, fromExpr)
683+
)
684+
or
680685
exists(int iIn |
681686
inModel.isParameter(iIn) and
682687
fromExpr = call.getArgument(iIn)

0 commit comments

Comments
 (0)