Skip to content

Commit 4f79398

Browse files
committed
Merge branch 'main' of github.com:github/codeql into 'main'
Conflicts: docs/codeql/query-help/codeql-cwe-coverage.rst
2 parents f020b2e + 7648815 commit 4f79398

File tree

51 files changed

+2761
-150
lines changed

Some content is hidden

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

51 files changed

+2761
-150
lines changed

.codeqlmanifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/tainted/qlpack.yml",
66
"*/ql/examples/qlpack.yml",
77
"*/upgrades/qlpack.yml",
8+
"javascript/ql/experimental/adaptivethreatmodeling/lib/qlpack.yml",
9+
"javascript/ql/experimental/adaptivethreatmodeling/src/qlpack.yml",
810
"misc/legacy-support/*/qlpack.yml",
911
"misc/suite-helpers/qlpack.yml" ] }

cpp/ql/src/Likely Bugs/Memory Management/NtohlArrayNoBound.qll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ class MallocSizeExpr extends BufferAccess, FunctionCall {
126126
}
127127

128128
class NetworkFunctionCall extends FunctionCall {
129-
NetworkFunctionCall() {
130-
getTarget().hasName("ntohd") or
131-
getTarget().hasName("ntohf") or
132-
getTarget().hasName("ntohl") or
133-
getTarget().hasName("ntohll") or
134-
getTarget().hasName("ntohs")
135-
}
129+
NetworkFunctionCall() { getTarget().hasName(["ntohd", "ntohf", "ntohl", "ntohll", "ntohs"]) }
136130
}
137131

138132
class NetworkToBufferSizeConfiguration extends DataFlow::Configuration {

cpp/ql/src/Security/CWE/CWE-497/ExposedSystemData.ql

Lines changed: 34 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ private predicate posixSystemInfo(FunctionCall source, Element use) {
103103
// - various filesystem parameters
104104
// int uname(struct utsname *buf)
105105
// - OS name and version
106-
(
107-
source.getTarget().hasName("confstr") or
108-
source.getTarget().hasName("statvfs") or
109-
source.getTarget().hasName("fstatvfs") or
110-
source.getTarget().hasName("uname")
111-
) and
106+
source.getTarget().hasName(["confstr", "statvfs", "fstatvfs", "uname"]) and
112107
use = source.getArgument(1)
113108
}
114109

@@ -128,14 +123,9 @@ private predicate posixPWInfo(FunctionCall source, Element use) {
128123
// struct group *getgrnam(const char *name);
129124
// struct group *getgrgid(gid_t);
130125
// struct group *getgrent(void);
131-
(
132-
source.getTarget().hasName("getpwnam") or
133-
source.getTarget().hasName("getpwuid") or
134-
source.getTarget().hasName("getpwent") or
135-
source.getTarget().hasName("getgrnam") or
136-
source.getTarget().hasName("getgrgid") or
137-
source.getTarget().hasName("getgrent")
138-
) and
126+
source
127+
.getTarget()
128+
.hasName(["getpwnam", "getpwuid", "getpwent", "getgrnam", "getgrgid", "getgrent"]) and
139129
use = source
140130
or
141131
// int getpwnam_r(const char *name, struct passwd *pwd,
@@ -146,31 +136,15 @@ private predicate posixPWInfo(FunctionCall source, Element use) {
146136
// char *buf, size_t buflen, struct group **result);
147137
// int getgrnam_r(const char *name, struct group *grp,
148138
// char *buf, size_t buflen, struct group **result);
149-
(
150-
source.getTarget().hasName("getpwnam_r") or
151-
source.getTarget().hasName("getpwuid_r") or
152-
source.getTarget().hasName("getgrgid_r") or
153-
source.getTarget().hasName("getgrnam_r")
154-
) and
155-
(
156-
use = source.getArgument(1) or
157-
use = source.getArgument(2) or
158-
use = source.getArgument(4)
159-
)
139+
source.getTarget().hasName(["getpwnam_r", "getpwuid_r", "getgrgid_r", "getgrnam_r"]) and
140+
use = source.getArgument([1, 2, 4])
160141
or
161142
// int getpwent_r(struct passwd *pwd, char *buffer, size_t bufsize,
162143
// struct passwd **result);
163144
// int getgrent_r(struct group *gbuf, char *buf,
164145
// size_t buflen, struct group **gbufp);
165-
(
166-
source.getTarget().hasName("getpwent_r") or
167-
source.getTarget().hasName("getgrent_r")
168-
) and
169-
(
170-
use = source.getArgument(0) or
171-
use = source.getArgument(1) or
172-
use = source.getArgument(3)
173-
)
146+
source.getTarget().hasName(["getpwent_r", "getgrent_r"]) and
147+
use = source.getArgument([0, 1, 3])
174148
}
175149

176150
/**
@@ -190,13 +164,11 @@ private predicate windowsSystemInfo(FunctionCall source, Element use) {
190164
// BOOL WINAPI GetVersionEx(_Inout_ LPOSVERSIONINFO lpVersionInfo);
191165
// void WINAPI GetSystemInfo(_Out_ LPSYSTEM_INFO lpSystemInfo);
192166
// void WINAPI GetNativeSystemInfo(_Out_ LPSYSTEM_INFO lpSystemInfo);
193-
(
194-
source.getTarget().hasGlobalName("GetVersionEx") or
195-
source.getTarget().hasGlobalName("GetVersionExA") or
196-
source.getTarget().hasGlobalName("GetVersionExW") or
197-
source.getTarget().hasGlobalName("GetSystemInfo") or
198-
source.getTarget().hasGlobalName("GetNativeSystemInfo")
199-
) and
167+
source
168+
.getTarget()
169+
.hasGlobalName([
170+
"GetVersionEx", "GetVersionExA", "GetVersionExW", "GetSystemInfo", "GetNativeSystemInfo"
171+
]) and
200172
use = source.getArgument(0)
201173
}
202174

@@ -216,11 +188,11 @@ private predicate windowsFolderPath(FunctionCall source, Element use) {
216188
// _In_ int csidl,
217189
// _In_ BOOL fCreate
218190
// );
219-
(
220-
source.getTarget().hasGlobalName("SHGetSpecialFolderPath") or
221-
source.getTarget().hasGlobalName("SHGetSpecialFolderPathA") or
222-
source.getTarget().hasGlobalName("SHGetSpecialFolderPathW")
223-
) and
191+
source
192+
.getTarget()
193+
.hasGlobalName([
194+
"SHGetSpecialFolderPath", "SHGetSpecialFolderPathA", "SHGetSpecialFolderPathW"
195+
]) and
224196
use = source.getArgument(1)
225197
or
226198
// HRESULT SHGetKnownFolderPath(
@@ -239,11 +211,7 @@ private predicate windowsFolderPath(FunctionCall source, Element use) {
239211
// _In_ DWORD dwFlags,
240212
// _Out_ LPTSTR pszPath
241213
// );
242-
(
243-
source.getTarget().hasGlobalName("SHGetFolderPath") or
244-
source.getTarget().hasGlobalName("SHGetFolderPathA") or
245-
source.getTarget().hasGlobalName("SHGetFolderPathW")
246-
) and
214+
source.getTarget().hasGlobalName(["SHGetFolderPath", "SHGetFolderPathA", "SHGetFolderPathW"]) and
247215
use = source.getArgument(4)
248216
or
249217
// HRESULT SHGetFolderPathAndSubDir(
@@ -254,11 +222,11 @@ private predicate windowsFolderPath(FunctionCall source, Element use) {
254222
// _In_ LPCTSTR pszSubDir,
255223
// _Out_ LPTSTR pszPath
256224
// );
257-
(
258-
source.getTarget().hasGlobalName("SHGetFolderPathAndSubDir") or
259-
source.getTarget().hasGlobalName("SHGetFolderPathAndSubDirA") or
260-
source.getTarget().hasGlobalName("SHGetFolderPathAndSubDirW")
261-
) and
225+
source
226+
.getTarget()
227+
.hasGlobalName([
228+
"SHGetFolderPathAndSubDir", "SHGetFolderPathAndSubDirA", "SHGetFolderPathAndSubDirW"
229+
]) and
262230
use = source.getArgument(5)
263231
}
264232

@@ -273,11 +241,7 @@ class WindowsFolderPath extends SystemData {
273241
}
274242

275243
private predicate logonUser(FunctionCall source, VariableAccess use) {
276-
(
277-
source.getTarget().hasGlobalName("LogonUser") or
278-
source.getTarget().hasGlobalName("LogonUserW") or
279-
source.getTarget().hasGlobalName("LogonUserA")
280-
) and
244+
source.getTarget().hasGlobalName(["LogonUser", "LogonUserW", "LogonUserA"]) and
281245
use = source.getAnArgument()
282246
}
283247

@@ -297,11 +261,7 @@ private predicate regQuery(FunctionCall source, VariableAccess use) {
297261
// _Out_opt_ LPTSTR lpValue,
298262
// _Inout_opt_ PLONG lpcbValue
299263
// );
300-
(
301-
source.getTarget().hasGlobalName("RegQueryValue") or
302-
source.getTarget().hasGlobalName("RegQueryValueA") or
303-
source.getTarget().hasGlobalName("RegQueryValueW")
304-
) and
264+
source.getTarget().hasGlobalName(["RegQueryValue", "RegQueryValueA", "RegQueryValueW"]) and
305265
use = source.getArgument(2)
306266
or
307267
// LONG WINAPI RegQueryMultipleValues(
@@ -311,11 +271,11 @@ private predicate regQuery(FunctionCall source, VariableAccess use) {
311271
// _Out_opt_ LPTSTR lpValueBuf,
312272
// _Inout_opt_ LPDWORD ldwTotsize
313273
// );
314-
(
315-
source.getTarget().hasGlobalName("RegQueryMultipleValues") or
316-
source.getTarget().hasGlobalName("RegQueryMultipleValuesA") or
317-
source.getTarget().hasGlobalName("RegQueryMultipleValuesW")
318-
) and
274+
source
275+
.getTarget()
276+
.hasGlobalName([
277+
"RegQueryMultipleValues", "RegQueryMultipleValuesA", "RegQueryMultipleValuesW"
278+
]) and
319279
use = source.getArgument(3)
320280
or
321281
// LONG WINAPI RegQueryValueEx(
@@ -326,11 +286,7 @@ private predicate regQuery(FunctionCall source, VariableAccess use) {
326286
// _Out_opt_ LPBYTE lpData,
327287
// _Inout_opt_ LPDWORD lpcbData
328288
// );
329-
(
330-
source.getTarget().hasGlobalName("RegQueryValueEx") or
331-
source.getTarget().hasGlobalName("RegQueryValueExA") or
332-
source.getTarget().hasGlobalName("RegQueryValueExW")
333-
) and
289+
source.getTarget().hasGlobalName(["RegQueryValueEx", "RegQueryValueExA", "RegQueryValueExW"]) and
334290
use = source.getArgument(4)
335291
or
336292
// LONG WINAPI RegGetValue(
@@ -342,11 +298,7 @@ private predicate regQuery(FunctionCall source, VariableAccess use) {
342298
// _Out_opt_ PVOID pvData,
343299
// _Inout_opt_ LPDWORD pcbData
344300
// );
345-
(
346-
source.getTarget().hasGlobalName("RegGetValue") or
347-
source.getTarget().hasGlobalName("RegGetValueA") or
348-
source.getTarget().hasGlobalName("RegGetValueW")
349-
) and
301+
source.getTarget().hasGlobalName(["RegGetValue", "RegGetValueA", "RegGetValueW"]) and
350302
use = source.getArgument(5)
351303
}
352304

@@ -408,12 +360,7 @@ private predicate socketOutput(FunctionCall call, Expr data) {
408360
// const struct sockaddr *dest_addr, socklen_t addrlen);
409361
// ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
410362
// int write(int handle, void *buffer, int nbyte);
411-
(
412-
call.getTarget().hasGlobalName("send") or
413-
call.getTarget().hasGlobalName("sendto") or
414-
call.getTarget().hasGlobalName("sendmsg") or
415-
call.getTarget().hasGlobalName("write")
416-
) and
363+
call.getTarget().hasGlobalName(["send", "sendto", "sendmsg", "write"]) and
417364
data = call.getArgument(1) and
418365
socketFileDescriptor(call.getArgument(0))
419366
)

cpp/ql/src/experimental/Security/CWE/CWE-273/PrivilegeDroppingOutoforder.ql

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ class SetuidLikeWrapperCall extends FunctionCall {
4444

4545
class CallBeforeSetuidFunctionCall extends FunctionCall {
4646
CallBeforeSetuidFunctionCall() {
47-
(
48-
getTarget().hasGlobalName("setgid") or
49-
getTarget().hasGlobalName("setresgid") or
50-
// Compatibility may require skipping initgroups and setgroups return checks.
51-
// A stricter best practice is to check the result and errnor for EPERM.
52-
getTarget().hasGlobalName("initgroups") or
53-
getTarget().hasGlobalName("setgroups")
54-
) and
47+
getTarget()
48+
.hasGlobalName([
49+
"setgid", "setresgid",
50+
// Compatibility may require skipping initgroups and setgroups return checks.
51+
// A stricter best practice is to check the result and errnor for EPERM.
52+
"initgroups", "setgroups"
53+
]) and
5554
// setgid/setresgid/etc with the root group are false positives.
5655
not argumentMayBeRoot(getArgument(0))
5756
}

cpp/ql/src/jsf/4.28 Portable Code/AV Rule 209.ql

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import cpp
1515

1616
from Element u, ArithmeticType at
1717
where
18-
(
19-
at.hasName("int") or
20-
at.hasName("short") or
21-
at.hasName("long") or
22-
at.hasName("float") or
23-
at.hasName("double")
24-
) and
18+
at.hasName(["int", "short", "long", "float", "double"]) and
2519
u = at.getATypeNameUse() and
2620
not at instanceof WideCharType
2721
select u, "AV Rule 209: The basic types of int, short, long, float and double shall not be used."

csharp/ql/lib/semmle/code/csharp/Conversion.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,16 @@ private predicate defaultDynamicConversion(Type fromType, Type toType) {
552552
fromType instanceof RefType and toType instanceof DynamicType
553553
}
554554

555+
pragma[noinline]
556+
private predicate systemDelegateBaseType(RefType t) {
557+
t = any(SystemDelegateClass c).getABaseType*()
558+
}
559+
555560
// This is a deliberate, small cartesian product, so we have manually lifted it to force the
556561
// evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
557562
pragma[noinline]
558563
private predicate defaultDelegateConversion(RefType fromType, RefType toType) {
559-
fromType instanceof DelegateType and toType = any(SystemDelegateClass c).getABaseType*()
564+
fromType instanceof DelegateType and systemDelegateBaseType(toType)
560565
}
561566

562567
private predicate convRefTypeRefType(RefType fromType, RefType toType) {

docs/codeql/codeql-cli/about-ql-packs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ QL packs are used to organize the files used in CodeQL analysis. They
77
contain queries, library files, query suites, and important metadata.
88

99
The `CodeQL repository <https://github.com/github/codeql>`__ contains QL packs for
10-
C/C++, C#, Java, JavaScript, and Python. The `CodeQL for Go
10+
C/C++, C#, Java, JavaScript, Python, and Ruby. The `CodeQL for Go
1111
<https://github.com/github/codeql-go/>`__ repository contains a QL pack for Go
1212
analysis. You can also make custom QL packs to contain your own queries and
1313
libraries.

docs/codeql/codeql-cli/creating-codeql-databases.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ Creating databases for non-compiled languages
8888
---------------------------------------------
8989

9090
The CodeQL CLI includes extractors to create databases for non-compiled
91-
languages---specifically, JavaScript (and TypeScript) and Python. These
92-
extractors are automatically invoked when you specify JavaScript or Python as
91+
languages---specifically, JavaScript (and TypeScript), Python, and Ruby. These
92+
extractors are automatically invoked when you specify JavaScript, Python, or Ruby as
9393
the ``--language`` option when executing ``database create``. When creating
9494
databases for these languages you must ensure that all additional dependencies
9595
are available.
9696

9797
.. pull-quote:: Important
9898

99-
When you run ``database create`` for JavaScript, TypeScript, and Python, you should not
99+
When you run ``database create`` for JavaScript, TypeScript, Python, and Ruby, you should not
100100
specify a ``--command`` option. Otherwise this overrides the normal
101101
extractor invocation, which will create an empty database. If you create
102102
databases for multiple languages and one of them is a compiled language,
@@ -116,6 +116,8 @@ Here, we have specified a ``--source-root`` path, which is the location where
116116
database creation is executed, but is not necessarily the checkout root of the
117117
codebase.
118118

119+
By default, files in ``node_modules`` and ``bower_components`` directories are not extracted.
120+
119121
Python
120122
~~~~~~
121123

@@ -127,14 +129,25 @@ When creating databases for Python you must ensure:
127129
packages that the codebase depends on.
128130
- You have installed the `virtualenv <https://pypi.org/project/virtualenv/>`__ pip module.
129131

130-
In the command line you must specify ``--language=python``. For example
132+
In the command line you must specify ``--language=python``. For example::
131133
::
132134

133135
codeql database create --language=python <output-folder>/python-database
134136

135-
executes the ``database create`` subcommand from the code's checkout root,
137+
This executes the ``database create`` subcommand from the code's checkout root,
136138
generating a new Python database at ``<output-folder>/python-database``.
137139

140+
Ruby
141+
~~~~
142+
143+
Creating databases for Ruby requires no additional dependencies.
144+
In the command line you must specify ``--language=ruby``. For example::
145+
146+
codeql database create --language=ruby --source-root <folder-to-extract> <output-folder>/ruby-database
147+
148+
Here, we have specified a ``--source-root`` path, which is the location where
149+
database creation is executed, but is not necessarily the checkout root of the
150+
codebase.
138151

139152
Creating databases for compiled languages
140153
-----------------------------------------

docs/codeql/codeql-cli/getting-started-with-the-codeql-cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ further options on the command line.
100100

101101
The `CodeQL repository <https://github.com/github/codeql>`__ contains
102102
the queries and libraries required for CodeQL analysis of C/C++, C#, Java,
103-
JavaScript/TypeScript, and Python.
103+
JavaScript/TypeScript, Python, and Ruby.
104104
Clone a copy of this repository into ``codeql-home``.
105105

106106
By default, the root of the cloned repository will be called ``codeql``.

docs/codeql/codeql-for-visual-studio-code/setting-up-codeql-in-visual-studio-code.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Using the starter workspace
7878
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7979
The starter workspace is a Git repository. It contains:
8080

81-
* The `repository of CodeQL libraries and queries <https://github.com/github/codeql>`__ for C/C++, C#, Java, JavaScript, and Python. This is included as a submodule, so it can be updated without affecting your custom queries.
81+
* The `repository of CodeQL libraries and queries <https://github.com/github/codeql>`__ for C/C++, C#, Java, JavaScript, Python, and Ruby. This is included as a submodule, so it can be updated without affecting your custom queries.
8282
* The `repository of CodeQL libraries and queries <https://github.com/github/codeql-go>`__ for Go. This is also included as a submodule.
8383
* A series of folders named ``codeql-custom-queries-<language>``. These are ready for you to start developing your own custom queries for each language, using the standard libraries. There are some example queries to get you started.
8484

0 commit comments

Comments
 (0)