mirror of
https://github.com/github/codeql.git
synced 2026-05-16 04:09:27 +02:00
Compare commits
285 Commits
codeql-cli
...
security-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
649e313cb5 | ||
|
|
76700d17d6 | ||
|
|
d4fdd50e2c | ||
|
|
1f9239089f | ||
|
|
b2a7a3ed30 | ||
|
|
2b7e599dc4 | ||
|
|
61d4d17225 | ||
|
|
cb524b6c19 | ||
|
|
5458c02cc2 | ||
|
|
33db0c13cd | ||
|
|
80eb0a2df6 | ||
|
|
437bba1e3c | ||
|
|
7d84cfacef | ||
|
|
39862740e0 | ||
|
|
579c955892 | ||
|
|
175c71221a | ||
|
|
60965b0d8c | ||
|
|
a27dac029f | ||
|
|
36abf8733e | ||
|
|
9e6f28e335 | ||
|
|
29aec0d770 | ||
|
|
c5193cf03f | ||
|
|
06514159be | ||
|
|
daad62c4e0 | ||
|
|
1ab75eb6f4 | ||
|
|
118840dad4 | ||
|
|
e36b42a03f | ||
|
|
95742aec69 | ||
|
|
64f8316a6d | ||
|
|
1e327289b2 | ||
|
|
50abb6e3a1 | ||
|
|
5c2bf68a05 | ||
|
|
40b74167e0 | ||
|
|
3c8ea167c4 | ||
|
|
6ed1016bb8 | ||
|
|
92b4eb7f02 | ||
|
|
e1028a2765 | ||
|
|
5c79ad2412 | ||
|
|
af0c32c01d | ||
|
|
605f28f741 | ||
|
|
b0975bb3ea | ||
|
|
451d36dc97 | ||
|
|
c9c8259ed0 | ||
|
|
5d827b6fc8 | ||
|
|
c37994089c | ||
|
|
254de76078 | ||
|
|
dedf765542 | ||
|
|
b359205d17 | ||
|
|
578ce1e512 | ||
|
|
7fbc62358e | ||
|
|
0e183ab4a4 | ||
|
|
fa36ba901a | ||
|
|
d269a7e717 | ||
|
|
216f204438 | ||
|
|
583d0889e2 | ||
|
|
5d05e4d224 | ||
|
|
0f24db8759 | ||
|
|
f8570bb293 | ||
|
|
cb736c8c82 | ||
|
|
972cc47f67 | ||
|
|
b4a2a9db25 | ||
|
|
b3bdf89fc2 | ||
|
|
4be183c7f6 | ||
|
|
fe57876fd8 | ||
|
|
97186b3d30 | ||
|
|
56ba0f080a | ||
|
|
392adf2a25 | ||
|
|
b29f35f564 | ||
|
|
64fed4cb10 | ||
|
|
b4f01c9afa | ||
|
|
53a320a810 | ||
|
|
bb447d7174 | ||
|
|
447f339857 | ||
|
|
92508beb82 | ||
|
|
f43d427875 | ||
|
|
bc7cc2f7ce | ||
|
|
da36508714 | ||
|
|
591ac38c31 | ||
|
|
54c79bff74 | ||
|
|
2e40d01397 | ||
|
|
44d2bf42d7 | ||
|
|
fd23e0bdda | ||
|
|
3b6cd0f681 | ||
|
|
9de8085571 | ||
|
|
2d0c9b6bf2 | ||
|
|
55723618a9 | ||
|
|
2965a1f204 | ||
|
|
5158e7964e | ||
|
|
36fe72246b | ||
|
|
4810308b16 | ||
|
|
77208bcc91 | ||
|
|
e2ed0d02b0 | ||
|
|
37dae67a0d | ||
|
|
419d25cbcf | ||
|
|
981c5deb57 | ||
|
|
d853f0c400 | ||
|
|
a6bb9ebb9f | ||
|
|
079c7e089d | ||
|
|
273e8ce4ef | ||
|
|
00235ed3b3 | ||
|
|
25b012db48 | ||
|
|
5f7d3d0d36 | ||
|
|
7be45e7c5e | ||
|
|
6e73d13670 | ||
|
|
2890fe6d61 | ||
|
|
7ed09904b4 | ||
|
|
aa52585120 | ||
|
|
89a5acf6e8 | ||
|
|
7f131c1f35 | ||
|
|
1008411594 | ||
|
|
d1457995dd | ||
|
|
a404faa302 | ||
|
|
7825a2cdfc | ||
|
|
1a4845f417 | ||
|
|
f93b68d4dc | ||
|
|
98d936d8b3 | ||
|
|
f341d5010d | ||
|
|
9b0ef2fe21 | ||
|
|
58d198261e | ||
|
|
646639bc73 | ||
|
|
f22b11881e | ||
|
|
45e1a61d7b | ||
|
|
e77117f902 | ||
|
|
929d9da4b4 | ||
|
|
7c13163413 | ||
|
|
15c103e42d | ||
|
|
dee974ff2d | ||
|
|
c37dbb2e68 | ||
|
|
3cfd30ef6f | ||
|
|
be39883166 | ||
|
|
afd2f58f9f | ||
|
|
697b2dcde8 | ||
|
|
0102d68f38 | ||
|
|
e0fcb15739 | ||
|
|
b96b665262 | ||
|
|
037e6369ce | ||
|
|
d7f26dfc18 | ||
|
|
fda750ef26 | ||
|
|
423ff32d04 | ||
|
|
6d4ddc0329 | ||
|
|
bc56d16c18 | ||
|
|
dfc91b8331 | ||
|
|
bb23866cec | ||
|
|
d35a501121 | ||
|
|
a43698802f | ||
|
|
310a2c8bb3 | ||
|
|
2656a52880 | ||
|
|
abeefcaced | ||
|
|
5aeaab7c6d | ||
|
|
11bf982728 | ||
|
|
32737a17fb | ||
|
|
172d6139e2 | ||
|
|
c281e54d22 | ||
|
|
57016ddbde | ||
|
|
7d2a60e910 | ||
|
|
5446532e1d | ||
|
|
acd4cf2878 | ||
|
|
e8d835b422 | ||
|
|
c7686b1838 | ||
|
|
cf5f838b13 | ||
|
|
e003b04061 | ||
|
|
cd57e61f65 | ||
|
|
91d28fb8b0 | ||
|
|
63f087a8e9 | ||
|
|
364d48948f | ||
|
|
17c4bbbc4e | ||
|
|
1b948ac2e2 | ||
|
|
4f2060f96b | ||
|
|
10be2735ec | ||
|
|
d90527bead | ||
|
|
9349e6922d | ||
|
|
eeae91e620 | ||
|
|
046aeaa38c | ||
|
|
8b756d7f1b | ||
|
|
650446f761 | ||
|
|
a5ebe8c600 | ||
|
|
8687c5c145 | ||
|
|
8a7d28a2ed | ||
|
|
4c21980d4f | ||
|
|
9635a36044 | ||
|
|
760231c004 | ||
|
|
c77c7b0a98 | ||
|
|
837f20108d | ||
|
|
157e4670fd | ||
|
|
79c1374925 | ||
|
|
1510048f7a | ||
|
|
d8165145c7 | ||
|
|
ebd38eaf3b | ||
|
|
b8c11503f0 | ||
|
|
0a86642056 | ||
|
|
4e3791dc0d | ||
|
|
720fbaf301 | ||
|
|
1510fe370d | ||
|
|
2329b31601 | ||
|
|
a460e3ad3d | ||
|
|
cc4827600b | ||
|
|
04b0682bbf | ||
|
|
fd8f745468 | ||
|
|
f130616369 | ||
|
|
d2b874f217 | ||
|
|
6874b8d4b3 | ||
|
|
affdedd840 | ||
|
|
0a6aef71a2 | ||
|
|
11304b2ae1 | ||
|
|
7f01586bf1 | ||
|
|
e5bce548de | ||
|
|
956311457d | ||
|
|
9b3ccade43 | ||
|
|
02eb447a35 | ||
|
|
a6b486a448 | ||
|
|
d73ba13b28 | ||
|
|
b39a3ab12c | ||
|
|
83477439a1 | ||
|
|
b7483a5394 | ||
|
|
322bdcb703 | ||
|
|
8ce5c46e05 | ||
|
|
675de07c3e | ||
|
|
ed34c96357 | ||
|
|
eb9b41acab | ||
|
|
a764a79090 | ||
|
|
c13ee0859a | ||
|
|
3d8e173c57 | ||
|
|
80ac2aff26 | ||
|
|
6c69c1aeeb | ||
|
|
ed2a8db8c9 | ||
|
|
9c3b7e81c7 | ||
|
|
a93132daae | ||
|
|
43ae7462b4 | ||
|
|
b44db460f6 | ||
|
|
cc63563a88 | ||
|
|
8e11abca40 | ||
|
|
32a8b9a857 | ||
|
|
480ce39618 | ||
|
|
ecbce88ec7 | ||
|
|
9ff894bf83 | ||
|
|
8159098dc0 | ||
|
|
1349bf7b0b | ||
|
|
0775d35591 | ||
|
|
3f215d0954 | ||
|
|
093c63ea3b | ||
|
|
5ce3f9d6ff | ||
|
|
a53cbc1631 | ||
|
|
a72b1340eb | ||
|
|
d33b04cd96 | ||
|
|
2ca95166d9 | ||
|
|
57bd3f3c14 | ||
|
|
fe0e7f5eac | ||
|
|
08c3bf26d5 | ||
|
|
3df23eecb6 | ||
|
|
c8a6e837b5 | ||
|
|
701b935564 | ||
|
|
6c24699403 | ||
|
|
adb1ed380a | ||
|
|
73e940de74 | ||
|
|
0200aedc2e | ||
|
|
26bac9f425 | ||
|
|
1385b22642 | ||
|
|
15206fd2ce | ||
|
|
98204a15a6 | ||
|
|
1a2e341b7c | ||
|
|
c8b1bc3a89 | ||
|
|
0a35feef76 | ||
|
|
eeac7e322a | ||
|
|
a0a1ddee86 | ||
|
|
f0ddfc9283 | ||
|
|
72f28513eb | ||
|
|
48975fa7d2 | ||
|
|
31eaa80f5b | ||
|
|
a93aabab40 | ||
|
|
919c6b4b0a | ||
|
|
10cc574289 | ||
|
|
01c13c4703 | ||
|
|
c5577cb09a | ||
|
|
502cf38fcc | ||
|
|
1b1c3f953b | ||
|
|
b366ffa69e | ||
|
|
95d1994196 | ||
|
|
f795d5e0d3 | ||
|
|
0521ef87da | ||
|
|
6fe8bafc7d | ||
|
|
872a000a33 | ||
|
|
8119fd2ad1 | ||
|
|
26b030f8cc | ||
|
|
dc73fcc4e8 | ||
|
|
dc58f6fa87 |
30
.github/workflows/close-stale.yml
vendored
Normal file
30
.github/workflows/close-stale.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: Mark stale issues
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
if: github.repository == 'github/codeql'
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue is stale because it has been open 14 days with no activity. Comment or remove the `Stale` label in order to avoid having this issue closed in 7 days.'
|
||||
close-issue-message: 'This issue was closed because it has been inactive for 7 days.'
|
||||
days-before-stale: 14
|
||||
days-before-close: 7
|
||||
only-labels: awaiting-response
|
||||
|
||||
# do not mark PRs as stale
|
||||
days-before-pr-stale: -1
|
||||
days-before-pr-close: -1
|
||||
|
||||
# Uncomment for dry-run
|
||||
# debug-only: true
|
||||
# operations-per-run: 1000
|
||||
@@ -56,6 +56,10 @@
|
||||
"csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImplConsistency.qll",
|
||||
"python/ql/src/semmle/python/dataflow/new/internal/DataFlowImplConsistency.qll"
|
||||
],
|
||||
"DataFlow Java/C# Flow Summaries": [
|
||||
"java/ql/src/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll",
|
||||
"csharp/ql/src/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll"
|
||||
],
|
||||
"SsaReadPosition Java/C#": [
|
||||
"java/ql/src/semmle/code/java/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll",
|
||||
"csharp/ql/src/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll"
|
||||
|
||||
2
cpp/change-notes/2021-04-13-arithmetic-queries.md
Normal file
2
cpp/change-notes/2021-04-13-arithmetic-queries.md
Normal file
@@ -0,0 +1,2 @@
|
||||
lgtm
|
||||
* The queries cpp/tainted-arithmetic, cpp/uncontrolled-arithmetic, and cpp/arithmetic-with-extreme-values have been improved to produce fewer false positives.
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/offset-use-before-range-check
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision medium
|
||||
* @tags reliability
|
||||
* security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/descriptor-may-not-be-closed
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @tags efficiency
|
||||
* security
|
||||
* external/cwe/cwe-775
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/descriptor-never-closed
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @tags efficiency
|
||||
* security
|
||||
* external/cwe/cwe-775
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/file-may-not-be-closed
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @tags efficiency
|
||||
* security
|
||||
* external/cwe/cwe-775
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/file-never-closed
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @tags efficiency
|
||||
* security
|
||||
* external/cwe/cwe-775
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/inconsistent-nullness-testing
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @tags reliability
|
||||
* security
|
||||
* external/cwe/cwe-476
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/memory-may-not-be-freed
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @tags efficiency
|
||||
* security
|
||||
* external/cwe/cwe-401
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/memory-never-freed
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @tags efficiency
|
||||
* security
|
||||
* external/cwe/cwe-401
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/missing-null-test
|
||||
* @problem.severity recommendation
|
||||
* @problem.security-severity 7.5
|
||||
* @tags reliability
|
||||
* security
|
||||
* external/cwe/cwe-476
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @description An object that was allocated with 'malloc' or 'new' is being freed using a mismatching 'free' or 'delete'.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @precision high
|
||||
* @id cpp/new-free-mismatch
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/overflow-calculated
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @tags reliability
|
||||
* security
|
||||
* external/cwe/cwe-131
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/overflow-destination
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @precision low
|
||||
* @tags reliability
|
||||
* security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* may result in a buffer overflow.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @precision medium
|
||||
* @id cpp/static-buffer-overflow
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* an instance of the type of the pointer may result in a buffer overflow
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision medium
|
||||
* @id cpp/allocation-too-small
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* multiple instances of the type of the pointer may result in a buffer overflow
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision medium
|
||||
* @id cpp/suspicious-allocation-size
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/use-after-free
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @tags reliability
|
||||
* security
|
||||
* external/cwe/cwe-416
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* to a larger type.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 8.1
|
||||
* @precision very-high
|
||||
* @id cpp/bad-addition-overflow-check
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* be a sign that the result can overflow the type converted from.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision high
|
||||
* @id cpp/integer-multiplication-cast-to-long
|
||||
* @tags reliability
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* use the width of the base type, leading to misaligned reads.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @precision high
|
||||
* @tags correctness
|
||||
* reliability
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* from an untrusted source, this can be used for exploits.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @problem.security-severity 9.8
|
||||
* @precision high
|
||||
* @id cpp/non-constant-format
|
||||
* @tags maintainability
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @description Using alloca in a loop can lead to a stack overflow
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @precision high
|
||||
* @id cpp/alloca-in-loop
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/improper-null-termination
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @tags security
|
||||
* external/cwe/cwe-170
|
||||
* external/cwe/cwe-665
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* as the third argument may result in a buffer overflow.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @precision medium
|
||||
* @id cpp/bad-strncpy-size
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* as the third argument may result in a buffer overflow.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @precision medium
|
||||
* @id cpp/unsafe-strncat
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/uninitialized-local
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @precision medium
|
||||
* @tags security
|
||||
* external/cwe/cwe-665
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* may result in a buffer overflow
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @precision medium
|
||||
* @id cpp/unsafe-strcat
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind path-problem
|
||||
* @precision low
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 8.6
|
||||
* @tags security external/cwe/cwe-20
|
||||
*/
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind path-problem
|
||||
* @precision low
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 8.6
|
||||
* @tags security external/cwe/cwe-20
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* attacker to access unexpected resources.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.8
|
||||
* @precision medium
|
||||
* @id cpp/path-injection
|
||||
* @tags security
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* to command injection.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.8
|
||||
* @precision low
|
||||
* @id cpp/command-line-injection
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* allows for a cross-site scripting vulnerability.
|
||||
* @kind path-problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 6.1
|
||||
* @precision high
|
||||
* @id cpp/cgi-xss
|
||||
* @tags security
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* to SQL Injection.
|
||||
* @kind path-problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.8
|
||||
* @precision high
|
||||
* @id cpp/sql-injection
|
||||
* @tags security
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* commands.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.2
|
||||
* @precision medium
|
||||
* @id cpp/uncontrolled-process-operation
|
||||
* @tags security
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/overflow-buffer
|
||||
* @problem.severity recommendation
|
||||
* @problem.security-severity 8.8
|
||||
* @tags security
|
||||
* external/cwe/cwe-119
|
||||
* external/cwe/cwe-121
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* overflow.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.1
|
||||
* @precision high
|
||||
* @id cpp/badly-bounded-write
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* of data written may overflow.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.1
|
||||
* @precision medium
|
||||
* @id cpp/overrunning-write
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* take extreme values.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.1
|
||||
* @precision medium
|
||||
* @id cpp/overrunning-write-with-float
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* of data written may overflow.
|
||||
* @kind path-problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.1
|
||||
* @precision medium
|
||||
* @id cpp/unbounded-write
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* a specific value to terminate the argument list.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @precision medium
|
||||
* @id cpp/unterminated-variadic-call
|
||||
* @tags reliability
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/unclear-array-index-validation
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @tags security
|
||||
* external/cwe/cwe-129
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* terminator can cause a buffer overrun.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.8
|
||||
* @precision high
|
||||
* @id cpp/no-space-for-terminator
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* or data representation problems.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @precision high
|
||||
* @id cpp/tainted-format-string
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* or data representation problems.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @precision high
|
||||
* @id cpp/tainted-format-string-through-global
|
||||
* @tags reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/user-controlled-null-termination-tainted
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 5.5
|
||||
* @tags security
|
||||
* external/cwe/cwe-170
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* not validated can cause overflows.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision low
|
||||
* @id cpp/tainted-arithmetic
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* validated can cause overflows.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision medium
|
||||
* @id cpp/uncontrolled-arithmetic
|
||||
* @tags security
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/arithmetic-with-extreme-values
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision low
|
||||
* @tags security
|
||||
* reliability
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @id cpp/comparison-with-wider-type
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @precision high
|
||||
* @tags reliability
|
||||
* security
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/integer-overflow-tainted
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision low
|
||||
* @tags security
|
||||
* external/cwe/cwe-190
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* user can result in integer overflow.
|
||||
* @kind path-problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 8.1
|
||||
* @precision medium
|
||||
* @id cpp/uncontrolled-allocation-size
|
||||
* @tags reliability
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/unsigned-difference-expression-compared-zero
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.2
|
||||
* @precision medium
|
||||
* @tags security
|
||||
* correctness
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* vulnerable to spoofing attacks.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.7
|
||||
* @precision medium
|
||||
* @id cpp/user-controlled-bypass
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* to an attacker.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @precision medium
|
||||
* @id cpp/cleartext-storage-buffer
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* to an attacker.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 6.5
|
||||
* @precision medium
|
||||
* @id cpp/cleartext-storage-file
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* database can expose it to an attacker.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 6.5
|
||||
* @precision medium
|
||||
* @id cpp/cleartext-storage-database
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* an attacker to compromise security.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 7.5
|
||||
* @precision medium
|
||||
* @id cpp/weak-cryptographic-algorithm
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* attackers to retrieve portions of memory.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 7.5
|
||||
* @precision very-high
|
||||
* @id cpp/openssl-heartbleed
|
||||
* @tags security
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* the two operations.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.0
|
||||
* @precision medium
|
||||
* @id cpp/toctou-race-condition
|
||||
* @tags security
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* @id cpp/unsafe-create-process-call
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 7.8
|
||||
* @precision medium
|
||||
* @msrc.severity important
|
||||
* @tags security
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/incorrect-string-type-conversion
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 9.8
|
||||
* @precision high
|
||||
* @tags security
|
||||
* external/cwe/cwe-704
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @description Creating a file that is world-writable can allow an attacker to write to the file.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.8
|
||||
* @precision medium
|
||||
* @id cpp/world-writable-file-creation
|
||||
* @tags security
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* @id cpp/unsafe-dacl-security-descriptor
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @problem.security-severity 7.8
|
||||
* @precision high
|
||||
* @tags security
|
||||
* external/cwe/cwe-732
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/infinite-loop-with-unsatisfiable-exit-condition
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @tags security
|
||||
* external/cwe/cwe-835
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/redundant-null-check-param
|
||||
* @problem.severity recommendation
|
||||
* @problem.security-severity 7.5
|
||||
* @tags reliability
|
||||
* security
|
||||
* external/cwe/cwe-476
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/late-check-of-function-argument
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.6
|
||||
* @precision medium
|
||||
* @tags correctness
|
||||
* security
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @description Use of one of the scanf functions without a specified length.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 9.8
|
||||
* @id cpp/memory-unsafe-function-scan
|
||||
* @tags reliability
|
||||
* security
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @description Using a multiplication result that may overflow in the size of an allocation may lead to buffer overflows when the allocated memory is used.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 8.1
|
||||
* @precision low
|
||||
* @tags security
|
||||
* correctness
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* from these methods is not checked.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @problem.security-severity 9.8
|
||||
* @id cpp/drop-linux-privileges-outoforder
|
||||
* @tags security
|
||||
* external/cwe/cwe-273
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @kind problem
|
||||
* @id cpp/memory-leak-on-failed-call-to-realloc
|
||||
* @problem.severity warning
|
||||
* @problem.security-severity 7.5
|
||||
* @precision medium
|
||||
* @tags correctness
|
||||
* security
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
if(len>0 & memset(buf,0,len)) return 1; // BAD: `memset` will be called regardless of the value of the `len` variable. moreover, one cannot be sure that it will happen after verification
|
||||
...
|
||||
if(len>0 && memset(buf,0,len)) return 1; // GOOD: `memset` will be called after the `len` variable has been checked.
|
||||
...
|
||||
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p>Using bitwise operations can be a mistake in some situations. For example, if parameters are evaluated in an expression and the function should be called only upon certain test results. These bitwise operations look suspicious and require developer attention.</p>
|
||||
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>We recommend that you evaluate the correctness of using the specified bit operations.</p>
|
||||
|
||||
</recommendation>
|
||||
<example>
|
||||
<p>The following example demonstrates the erroneous and fixed use of bit and logical operations.</p>
|
||||
<sample src="InsufficientControlFlowManagementWhenUsingBitOperations.c" />
|
||||
|
||||
</example>
|
||||
<references>
|
||||
|
||||
<li>
|
||||
CWE Common Weakness Enumeration:
|
||||
<a href="https://cwe.mitre.org/data/definitions/691.html"> CWE-691: Insufficient Control Flow Management</a>.
|
||||
</li>
|
||||
|
||||
</references>
|
||||
</qhelp>
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @name Errors When Using Bit Operations
|
||||
* @description Unlike the binary operations `||` and `&&`, there is no sequence point after evaluating an
|
||||
* operand of a bitwise operation like `|` or `&`. If left-to-right evaluation is expected this may be confusing.
|
||||
* @kind problem
|
||||
* @id cpp/errors-when-using-bit-operations
|
||||
* @problem.severity warning
|
||||
* @precision medium
|
||||
* @tags correctness
|
||||
* security
|
||||
* external/cwe/cwe-691
|
||||
*/
|
||||
|
||||
import cpp
|
||||
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
|
||||
|
||||
/**
|
||||
* Dangerous uses of bit operations.
|
||||
* For example: `if(intA>0 & intA<10 & charBuf&myFunc(charBuf[intA]))`.
|
||||
* In this case, the function will be called in any case, and even the sequence of the call is not guaranteed.
|
||||
*/
|
||||
class DangerousBitOperations extends BinaryBitwiseOperation {
|
||||
FunctionCall bfc;
|
||||
|
||||
/**
|
||||
* The assignment indicates the conscious use of the bit operator.
|
||||
* Use in comparison, conversion, or return value indicates conscious use of the bit operator.
|
||||
* The use of shifts and bitwise operations on any element of an expression indicates a conscious use of the bitwise operator.
|
||||
*/
|
||||
DangerousBitOperations() {
|
||||
bfc = this.getRightOperand() and
|
||||
not this.getParent*() instanceof Assignment and
|
||||
not this.getParent*() instanceof Initializer and
|
||||
not this.getParent*() instanceof ReturnStmt and
|
||||
not this.getParent*() instanceof EqualityOperation and
|
||||
not this.getParent*() instanceof UnaryLogicalOperation and
|
||||
not this.getParent*() instanceof BinaryLogicalOperation and
|
||||
not this.getAChild*() instanceof BitwiseXorExpr and
|
||||
not this.getAChild*() instanceof LShiftExpr and
|
||||
not this.getAChild*() instanceof RShiftExpr
|
||||
}
|
||||
|
||||
/** Holds when part of a bit expression is used in a logical operation. */
|
||||
predicate useInLogicalOperations() {
|
||||
exists(BinaryLogicalOperation blop, Expr exp |
|
||||
blop.getAChild*() = exp and
|
||||
exp.(FunctionCall).getTarget() = bfc.getTarget() and
|
||||
not exp.getParent() instanceof ComparisonOperation and
|
||||
not exp.getParent() instanceof BinaryBitwiseOperation
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds when part of a bit expression is used as part of another supply. For example, as an argument to another function. */
|
||||
predicate useInOtherCalls() {
|
||||
bfc.hasQualifier() or
|
||||
bfc.getTarget() instanceof Operator or
|
||||
exists(FunctionCall fc | fc.getAnArgument().getAChild*() = this) or
|
||||
bfc.getTarget() instanceof BuiltInFunction
|
||||
}
|
||||
|
||||
/** Holds when the bit expression contains both arguments and a function call. */
|
||||
predicate dangerousArgumentChecking() {
|
||||
not this.getLeftOperand() instanceof Call and
|
||||
globalValueNumber(this.getLeftOperand().getAChild*()) = globalValueNumber(bfc.getAnArgument())
|
||||
}
|
||||
|
||||
/** Holds when function calls are present in the bit expression. */
|
||||
predicate functionCallsInBitsExpression() {
|
||||
this.getLeftOperand().getAChild*() instanceof FunctionCall
|
||||
}
|
||||
}
|
||||
|
||||
from DangerousBitOperations dbo
|
||||
where
|
||||
not dbo.useInOtherCalls() and
|
||||
dbo.useInLogicalOperations() and
|
||||
(not dbo.functionCallsInBitsExpression() or dbo.dangerousArgumentChecking())
|
||||
select dbo, "This bitwise operation appears in a context where a Boolean operation is expected."
|
||||
@@ -0,0 +1,11 @@
|
||||
if(len=funcReadData()==0) return 1; // BAD: variable `len` will not equal the value returned by function `funcReadData()`
|
||||
...
|
||||
if((len=funcReadData())==0) return 1; // GOOD: variable `len` equal the value returned by function `funcReadData()`
|
||||
...
|
||||
bool a=true;
|
||||
a++;// BAD: variable `a` does not change its meaning
|
||||
bool b;
|
||||
b=-a;// BAD: variable `b` equal `true`
|
||||
...
|
||||
a=false;// GOOD: variable `a` equal `false`
|
||||
b=!a;// GOOD: variable `b` equal `false`
|
||||
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p>Finding places of confusing use of boolean type. For example, a unary minus does not work before a boolean type and an increment always gives true.</p>
|
||||
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>we recommend making the code simpler.</p>
|
||||
|
||||
</recommendation>
|
||||
<example>
|
||||
<p>The following example demonstrates erroneous and fixed methods for using a boolean data type.</p>
|
||||
<sample src="OperatorPrecedenceLogicErrorWhenUseBoolType.c" />
|
||||
|
||||
</example>
|
||||
<references>
|
||||
|
||||
<li>
|
||||
CERT C Coding Standard:
|
||||
<a href="https://wiki.sei.cmu.edu/confluence/display/c/EXP00-C.+Use+parentheses+for+precedence+of+operation">EXP00-C. Use parentheses for precedence of operation</a>.
|
||||
</li>
|
||||
|
||||
</references>
|
||||
</qhelp>
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @name Operator Precedence Logic Error When Use Bool Type
|
||||
* @description --Finding places of confusing use of boolean type.
|
||||
* --For example, a unary minus does not work before a boolean type and an increment always gives true.
|
||||
* @kind problem
|
||||
* @id cpp/operator-precedence-logic-error-when-use-bool-type
|
||||
* @problem.severity warning
|
||||
* @precision medium
|
||||
* @tags correctness
|
||||
* security
|
||||
* external/cwe/cwe-783
|
||||
* external/cwe/cwe-480
|
||||
*/
|
||||
|
||||
import cpp
|
||||
import semmle.code.cpp.valuenumbering.HashCons
|
||||
|
||||
/** Holds if `exp` increments a boolean value. */
|
||||
predicate incrementBoolType(IncrementOperation exp) {
|
||||
exp.getOperand().getType() instanceof BoolType
|
||||
}
|
||||
|
||||
/** Holds if `exp` applies the unary minus operator to a boolean type. */
|
||||
predicate revertSignBoolType(UnaryMinusExpr exp) {
|
||||
exp.getAnOperand().getType() instanceof BoolType and
|
||||
exp.getFullyConverted().getType() instanceof BoolType
|
||||
}
|
||||
|
||||
/** Holds, if this is an expression, uses comparison and assignment outside of execution precedence. */
|
||||
predicate assignBoolType(Expr exp) {
|
||||
exists(ComparisonOperation co |
|
||||
exp.(AssignExpr).getRValue() = co and
|
||||
exp.isCondition() and
|
||||
not co.isParenthesised() and
|
||||
not exp.(AssignExpr).getLValue().getType() instanceof BoolType and
|
||||
not exists(Expr exbl |
|
||||
hashCons(exbl.(AssignExpr).getLValue()) = hashCons(exp.(AssignExpr).getLValue()) and
|
||||
not exbl.isCondition() and
|
||||
exbl.(AssignExpr).getRValue().getType() instanceof BoolType and
|
||||
exbl.(AssignExpr).getLValue().getType() = exp.(AssignExpr).getLValue().getType()
|
||||
) and
|
||||
co.getLeftOperand() instanceof FunctionCall and
|
||||
not co.getRightOperand().getType() instanceof BoolType and
|
||||
not co.getRightOperand().getValue() = "0" and
|
||||
not co.getRightOperand().getValue() = "1"
|
||||
)
|
||||
}
|
||||
|
||||
from Expr exp
|
||||
where
|
||||
incrementBoolType(exp) or
|
||||
revertSignBoolType(exp) or
|
||||
assignBoolType(exp)
|
||||
select exp, "this expression needs attention"
|
||||
@@ -3,7 +3,7 @@
|
||||
* @description The expression `buffer [strlen (buffer)] = 0` is potentially dangerous, if the variable `buffer` does not have a terminal zero, then access beyond the bounds of the allocated memory is possible, which will lead to undefined behavior.
|
||||
* If terminal zero is present, then the specified expression is meaningless.
|
||||
* @kind problem
|
||||
* @id cpp/access-memory-location-after-end-buffer
|
||||
* @id cpp/access-memory-location-after-end-buffer-strlen
|
||||
* @problem.severity warning
|
||||
* @precision medium
|
||||
* @tags correctness
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @name Access Of Memory Location After The End Of A Buffer Using Strncat
|
||||
* @description Calls of the form `strncat(dest, source, sizeof (dest) - strlen (dest))` set the third argument to one more than possible. So when `dest` is full, the expression `sizeof(dest) - strlen (dest)` will be equal to one, and not zero as the programmer might think. Making a call of this type may result in a zero byte being written just outside the `dest` buffer.
|
||||
* @kind problem
|
||||
* @id cpp/access-memory-location-after-end-buffer
|
||||
* @id cpp/access-memory-location-after-end-buffer-strncat
|
||||
* @problem.severity warning
|
||||
* @precision medium
|
||||
* @tags correctness
|
||||
@@ -11,54 +11,32 @@
|
||||
*/
|
||||
|
||||
import cpp
|
||||
import semmle.code.cpp.models.implementations.Strcat
|
||||
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
|
||||
|
||||
/**
|
||||
* A call to `strncat` of the form `strncat(buff, str, someExpr - strlen(buf))`, for some expression `someExpr` equal to `sizeof(buff)`.
|
||||
* Holds if `call` is a call to `strncat` such that `sizeArg` and `destArg` are the size and
|
||||
* destination arguments, respectively.
|
||||
*/
|
||||
class WrongCallStrncat extends FunctionCall {
|
||||
Expr leftsomeExpr;
|
||||
|
||||
WrongCallStrncat() {
|
||||
this.getTarget().hasGlobalOrStdName("strncat") and
|
||||
// the expression of the first argument in `strncat` and `strnlen` is identical
|
||||
globalValueNumber(this.getArgument(0)) =
|
||||
globalValueNumber(this.getArgument(2).(SubExpr).getRightOperand().(StrlenCall).getStringExpr()) and
|
||||
// using a string constant often speaks of manually calculating the length of the required buffer.
|
||||
(
|
||||
not this.getArgument(1) instanceof StringLiteral and
|
||||
not this.getArgument(1) instanceof CharLiteral
|
||||
) and
|
||||
// for use in predicates
|
||||
leftsomeExpr = this.getArgument(2).(SubExpr).getLeftOperand()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the left side of the expression `someExpr` equal to `sizeof(buf)`.
|
||||
*/
|
||||
predicate isExpressionEqualSizeof() {
|
||||
// the left side of the expression `someExpr` is `sizeof(buf)`.
|
||||
globalValueNumber(this.getArgument(0)) =
|
||||
globalValueNumber(leftsomeExpr.(SizeofExprOperator).getExprOperand())
|
||||
or
|
||||
// value of the left side of the expression `someExpr` equal `sizeof(buf)` value, and `buf` is array.
|
||||
leftsomeExpr.getValue().toInt() = this.getArgument(0).getType().getSize()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the left side of the expression `someExpr` equal to variable containing the length of the memory allocated for the buffer.
|
||||
*/
|
||||
predicate isVariableEqualValueSizegBuffer() {
|
||||
// the left side of expression `someExpr` is the variable that was used in the function of allocating memory for the buffer`.
|
||||
exists(AllocationExpr alc |
|
||||
leftsomeExpr.(VariableAccess).getTarget() =
|
||||
alc.(FunctionCall).getArgument(0).(VariableAccess).getTarget()
|
||||
)
|
||||
}
|
||||
predicate interestringCallWithArgs(Call call, Expr sizeArg, Expr destArg) {
|
||||
exists(StrcatFunction strcat |
|
||||
strcat = call.getTarget() and
|
||||
sizeArg = call.getArgument(strcat.getParamSize()) and
|
||||
destArg = call.getArgument(strcat.getParamDest())
|
||||
)
|
||||
}
|
||||
|
||||
from WrongCallStrncat sc
|
||||
from FunctionCall call, Expr sizeArg, Expr destArg, SubExpr sub, int n
|
||||
where
|
||||
sc.isExpressionEqualSizeof() or
|
||||
sc.isVariableEqualValueSizegBuffer()
|
||||
select sc, "if the used buffer is full, writing out of the buffer is possible"
|
||||
interestringCallWithArgs(call, sizeArg, destArg) and
|
||||
// The destination buffer is an array of size n
|
||||
destArg.getUnspecifiedType().(ArrayType).getSize() = n and
|
||||
// The size argument is equivalent to a subtraction
|
||||
globalValueNumber(sizeArg).getAnExpr() = sub and
|
||||
// ... where the left side of the subtraction is the constant n
|
||||
globalValueNumber(sub.getLeftOperand()).getAnExpr().getValue().toInt() = n and
|
||||
// ... and the right side of the subtraction is a call to `strlen` where the argument is the
|
||||
// destination buffer.
|
||||
globalValueNumber(sub.getRightOperand()).getAnExpr().(StrlenCall).getStringExpr() =
|
||||
globalValueNumber(destArg).getAnExpr()
|
||||
select call, "Possible out-of-bounds write due to incorrect size argument."
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
private import cpp
|
||||
private import semmle.code.cpp.models.interfaces.PointerWrapper
|
||||
|
||||
/**
|
||||
* Holds if `f` is an instantiation of the `std::move` or `std::forward`
|
||||
@@ -94,6 +95,12 @@ private predicate pointerToPointerStep(Expr pointerIn, Expr pointerOut) {
|
||||
|
||||
private predicate lvalueToReferenceStep(Expr lvalueIn, Expr referenceOut) {
|
||||
lvalueIn.getConversion() = referenceOut.(ReferenceToExpr)
|
||||
or
|
||||
exists(PointerWrapper wrapper, Call call | call = referenceOut |
|
||||
referenceOut.getUnspecifiedType() instanceof ReferenceType and
|
||||
call = wrapper.getAnUnwrapperFunction().getACallToThisFunction() and
|
||||
lvalueIn = call.getQualifier().getFullyConverted()
|
||||
)
|
||||
}
|
||||
|
||||
private predicate referenceToLvalueStep(Expr referenceIn, Expr lvalueOut) {
|
||||
@@ -106,6 +113,13 @@ private predicate referenceToPointerStep(Expr referenceIn, Expr pointerOut) {
|
||||
stdAddressOf(call.getTarget()) and
|
||||
referenceIn = call.getArgument(0).getFullyConverted()
|
||||
)
|
||||
or
|
||||
exists(CopyConstructor copy, Call call | call = pointerOut |
|
||||
copy.getDeclaringType() instanceof PointerWrapper and
|
||||
call.getTarget() = copy and
|
||||
// The 0'th argument is the value being copied.
|
||||
referenceIn = call.getArgument(0).getFullyConverted()
|
||||
)
|
||||
}
|
||||
|
||||
private predicate referenceToReferenceStep(Expr referenceIn, Expr referenceOut) {
|
||||
@@ -190,6 +204,19 @@ private predicate pointerToUpdate(Expr pointer, Expr outer, ControlFlowNode node
|
||||
// See the `lvalueToUpdate` case for an explanation of this conjunct.
|
||||
call.getType().isDeeplyConstBelow()
|
||||
)
|
||||
or
|
||||
// Pointer wrappers behave as raw pointers for dataflow purposes.
|
||||
outer = call.getAnArgument().getFullyConverted() and
|
||||
exists(PointerWrapper wrapper | wrapper = outer.getType().stripTopLevelSpecifiers() |
|
||||
not wrapper.pointsToConst()
|
||||
)
|
||||
or
|
||||
outer = call.getQualifier().getFullyConverted() and
|
||||
outer.getUnspecifiedType() instanceof PointerWrapper and
|
||||
not (
|
||||
call.getTarget().hasSpecifier("const") and
|
||||
call.getType().isDeeplyConstBelow()
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(PointerFieldAccess fa |
|
||||
@@ -218,7 +245,9 @@ private predicate referenceToUpdate(Expr reference, Expr outer, ControlFlowNode
|
||||
not stdIdentityFunction(call.getTarget()) and
|
||||
not stdAddressOf(call.getTarget()) and
|
||||
exists(ReferenceType rt | rt = outer.getType().stripTopLevelSpecifiers() |
|
||||
not rt.getBaseType().isConst()
|
||||
not rt.getBaseType().isConst() or
|
||||
rt.getBaseType().getUnspecifiedType() =
|
||||
any(PointerWrapper wrapper | not wrapper.pointsToConst())
|
||||
)
|
||||
) and
|
||||
reference = outer
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -46,7 +46,7 @@ class Node extends TNode {
|
||||
/**
|
||||
* INTERNAL: Do not use. Alternative name for `getFunction`.
|
||||
*/
|
||||
final Function getEnclosingCallable() { result = unique(Function f | f = this.getFunction() | f) }
|
||||
final Function getEnclosingCallable() { result = this.getFunction() }
|
||||
|
||||
/** Gets the type of this node. */
|
||||
Type getType() { none() } // overridden in subclasses
|
||||
@@ -324,7 +324,7 @@ private class VariablePartialDefinitionNode extends PartialDefinitionNode {
|
||||
* A synthetic data flow node used for flow into a collection when an iterator
|
||||
* write occurs in a callee.
|
||||
*/
|
||||
class IteratorPartialDefinitionNode extends PartialDefinitionNode {
|
||||
private class IteratorPartialDefinitionNode extends PartialDefinitionNode {
|
||||
override IteratorPartialDefinition pd;
|
||||
|
||||
override Node getPreUpdateNode() { pd.definesExpressions(_, result.asExpr()) }
|
||||
@@ -715,6 +715,7 @@ private predicate exprToDefinitionByReferenceStep(Expr exprIn, Expr argOut) {
|
||||
}
|
||||
|
||||
private module FieldFlow {
|
||||
private import DataFlowImplCommon
|
||||
private import DataFlowImplLocal
|
||||
private import DataFlowPrivate
|
||||
|
||||
@@ -747,7 +748,7 @@ private module FieldFlow {
|
||||
exists(FieldConfiguration cfg | cfg.hasFlow(node1, node2)) and
|
||||
// This configuration should not be able to cross function boundaries, but
|
||||
// we double-check here just to be sure.
|
||||
node1.getEnclosingCallable() = node2.getEnclosingCallable()
|
||||
getNodeEnclosingCallable(node1) = getNodeEnclosingCallable(node2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ private import semmle.code.cpp.controlflow.SSA
|
||||
private import semmle.code.cpp.dataflow.internal.SubBasicBlocks
|
||||
private import semmle.code.cpp.dataflow.internal.AddressFlow
|
||||
private import semmle.code.cpp.models.implementations.Iterator
|
||||
private import semmle.code.cpp.models.interfaces.PointerWrapper
|
||||
|
||||
/**
|
||||
* A conceptual variable that is assigned only once, like an SSA variable. This
|
||||
@@ -158,18 +159,14 @@ private module PartialDefinitions {
|
||||
Expr innerDefinedExpr;
|
||||
|
||||
IteratorPartialDefinition() {
|
||||
exists(Expr convertedInner |
|
||||
not this instanceof Conversion and
|
||||
valueToUpdate(convertedInner, this.getFullyConverted(), node) and
|
||||
innerDefinedExpr = convertedInner.getUnconverted() and
|
||||
(
|
||||
innerDefinedExpr.(Call).getQualifier() = getAnIteratorAccess(collection)
|
||||
or
|
||||
innerDefinedExpr.(Call).getQualifier() = collection.getAnAccess() and
|
||||
collection instanceof IteratorParameter
|
||||
) and
|
||||
innerDefinedExpr.(Call).getTarget() instanceof IteratorPointerDereferenceMemberOperator
|
||||
)
|
||||
innerDefinedExpr = getInnerDefinedExpr(this, node) and
|
||||
(
|
||||
innerDefinedExpr.(Call).getQualifier() = getAnIteratorAccess(collection)
|
||||
or
|
||||
innerDefinedExpr.(Call).getQualifier() = collection.getAnAccess() and
|
||||
collection instanceof IteratorParameter
|
||||
) and
|
||||
innerDefinedExpr.(Call).getTarget() instanceof IteratorPointerDereferenceMemberOperator
|
||||
or
|
||||
// iterators passed by value without a copy constructor
|
||||
exists(Call call |
|
||||
@@ -207,16 +204,18 @@ private module PartialDefinitions {
|
||||
}
|
||||
}
|
||||
|
||||
private Expr getInnerDefinedExpr(Expr e, ControlFlowNode node) {
|
||||
not e instanceof Conversion and
|
||||
exists(Expr convertedInner |
|
||||
valueToUpdate(convertedInner, e.getFullyConverted(), node) and
|
||||
result = convertedInner.getUnconverted()
|
||||
)
|
||||
}
|
||||
|
||||
class VariablePartialDefinition extends PartialDefinition {
|
||||
Expr innerDefinedExpr;
|
||||
|
||||
VariablePartialDefinition() {
|
||||
not this instanceof Conversion and
|
||||
exists(Expr convertedInner |
|
||||
valueToUpdate(convertedInner, this.getFullyConverted(), node) and
|
||||
innerDefinedExpr = convertedInner.getUnconverted()
|
||||
)
|
||||
}
|
||||
VariablePartialDefinition() { innerDefinedExpr = getInnerDefinedExpr(this, node) }
|
||||
|
||||
deprecated override predicate partiallyDefines(Variable v) {
|
||||
innerDefinedExpr = v.getAnAccess()
|
||||
@@ -296,7 +295,8 @@ module FlowVar_internal {
|
||||
// treating them as immutable, but for data flow it gives better results in
|
||||
// practice to make the variable synonymous with its contents.
|
||||
not v.getUnspecifiedType() instanceof ReferenceType and
|
||||
not v instanceof IteratorParameter
|
||||
not v instanceof IteratorParameter and
|
||||
not v instanceof PointerWrapperParameter
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -644,10 +644,19 @@ module FlowVar_internal {
|
||||
predicate parameterIsNonConstReference(Parameter p) {
|
||||
exists(ReferenceType refType |
|
||||
refType = p.getUnderlyingType() and
|
||||
not refType.getBaseType().isConst()
|
||||
(
|
||||
not refType.getBaseType().isConst()
|
||||
or
|
||||
// A field of a parameter of type `const std::shared_ptr<A>& p` can still be changed even though
|
||||
// the base type of the reference is `const`.
|
||||
refType.getBaseType().getUnspecifiedType() =
|
||||
any(PointerWrapper wrapper | not wrapper.pointsToConst())
|
||||
)
|
||||
)
|
||||
or
|
||||
p instanceof IteratorParameter
|
||||
or
|
||||
p instanceof PointerWrapperParameter
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -836,6 +845,10 @@ module FlowVar_internal {
|
||||
IteratorParameter() { this.getUnspecifiedType() instanceof Iterator }
|
||||
}
|
||||
|
||||
class PointerWrapperParameter extends Parameter {
|
||||
PointerWrapperParameter() { this.getUnspecifiedType() instanceof PointerWrapper }
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `v` is initialized to have value `assignedExpr`.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
private import semmle.code.cpp.models.interfaces.DataFlow
|
||||
private import semmle.code.cpp.models.interfaces.Taint
|
||||
private import semmle.code.cpp.models.interfaces.Iterator
|
||||
private import semmle.code.cpp.models.interfaces.PointerWrapper
|
||||
|
||||
private module DataFlow {
|
||||
import semmle.code.cpp.dataflow.internal.DataFlowUtil
|
||||
@@ -141,7 +142,10 @@ private predicate noFlowFromChildExpr(Expr e) {
|
||||
or
|
||||
e instanceof LogicalOrExpr
|
||||
or
|
||||
e instanceof Call
|
||||
// Allow taint from `operator*` on smart pointers.
|
||||
exists(Call call | e = call |
|
||||
not call.getTarget() = any(PointerWrapper wrapper).getAnUnwrapperFunction()
|
||||
)
|
||||
or
|
||||
e instanceof SizeofOperator
|
||||
or
|
||||
|
||||
@@ -314,6 +314,7 @@ class OverloadedPointerDereferenceFunction extends Function {
|
||||
* T1 operator*(const T2 &);
|
||||
* T1 a; T2 b;
|
||||
* a = *b;
|
||||
* ```
|
||||
*/
|
||||
class OverloadedPointerDereferenceExpr extends FunctionCall {
|
||||
OverloadedPointerDereferenceExpr() {
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -2133,11 +2133,8 @@ private module Stage4 {
|
||||
|
||||
bindingset[node, cc, config]
|
||||
private LocalCc getLocalCc(Node node, Cc cc, Configuration config) {
|
||||
exists(Cc cc0 |
|
||||
cc = pragma[only_bind_into](cc0) and
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(cc0, getNodeEnclosingCallable(node))
|
||||
)
|
||||
localFlowEntry(node, config) and
|
||||
result = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(node))
|
||||
}
|
||||
|
||||
private predicate localStep(
|
||||
@@ -3132,7 +3129,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
|
||||
conf = mid.getConfiguration() and
|
||||
cc = mid.getCallContext() and
|
||||
sc = mid.getSummaryCtx() and
|
||||
localCC = getLocalCallContext(cc, getNodeEnclosingCallable(midnode)) and
|
||||
localCC = getLocalCallContext(pragma[only_bind_out](cc), getNodeEnclosingCallable(midnode)) and
|
||||
ap0 = mid.getAp()
|
||||
|
|
||||
localFlowBigStep(midnode, node, true, _, conf, localCC) and
|
||||
|
||||
@@ -362,15 +362,22 @@ private class ExplicitFieldStoreQualifierNode extends PartialDefinitionNode {
|
||||
|
||||
/**
|
||||
* Not every store instruction generates a chi instruction that we can attach a PostUpdateNode to.
|
||||
* For instance, an update to a field of a struct containing only one field. For these cases we
|
||||
* attach the PostUpdateNode to the store instruction. There's no obvious pre update node for this case
|
||||
* (as the entire memory is updated), so `getPreUpdateNode` is implemented as `none()`.
|
||||
* For instance, an update to a field of a struct containing only one field. Even if the store does
|
||||
* have a chi instruction, a subsequent use of the result of the store may be linked directly to the
|
||||
* result of the store as an inexact definition if the store totally overlaps the use. For these
|
||||
* cases we attach the PostUpdateNode to the store instruction. There's no obvious pre update node
|
||||
* for this case (as the entire memory is updated), so `getPreUpdateNode` is implemented as
|
||||
* `none()`.
|
||||
*/
|
||||
private class ExplicitSingleFieldStoreQualifierNode extends PartialDefinitionNode {
|
||||
override StoreInstruction instr;
|
||||
|
||||
ExplicitSingleFieldStoreQualifierNode() {
|
||||
not exists(ChiInstruction chi | chi.getPartial() = instr) and
|
||||
(
|
||||
instr.getAUse().isDefinitionInexact()
|
||||
or
|
||||
not exists(ChiInstruction chi | chi.getPartial() = instr)
|
||||
) and
|
||||
// Without this condition any store would create a `PostUpdateNode`.
|
||||
instr.getDestinationAddress() instanceof FieldAddressInstruction
|
||||
}
|
||||
|
||||
@@ -6,34 +6,7 @@ private import semmle.code.cpp.ir.ValueNumbering
|
||||
private import semmle.code.cpp.ir.IR
|
||||
private import semmle.code.cpp.ir.dataflow.DataFlow
|
||||
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
|
||||
|
||||
/**
|
||||
* Gets a short ID for an IR dataflow node.
|
||||
* - For `Instruction`s, this is just the result ID of the instruction (e.g. `m128`).
|
||||
* - For `Operand`s, this is the label of the operand, prefixed with the result ID of the
|
||||
* instruction and a dot (e.g. `m128.left`).
|
||||
* - For `Variable`s, this is the qualified name of the variable.
|
||||
*/
|
||||
private string nodeId(DataFlow::Node node, int order1, int order2) {
|
||||
exists(Instruction instruction | instruction = node.asInstruction() |
|
||||
result = instruction.getResultId() and
|
||||
order1 = instruction.getBlock().getDisplayIndex() and
|
||||
order2 = instruction.getDisplayIndexInBlock()
|
||||
)
|
||||
or
|
||||
exists(Operand operand, Instruction instruction |
|
||||
operand = node.asOperand() and
|
||||
instruction = operand.getUse()
|
||||
|
|
||||
result = instruction.getResultId() + "." + operand.getDumpId() and
|
||||
order1 = instruction.getBlock().getDisplayIndex() and
|
||||
order2 = instruction.getDisplayIndexInBlock()
|
||||
)
|
||||
or
|
||||
result = "var(" + node.asVariable().getQualifiedName() + ")" and
|
||||
order1 = 1000000 and
|
||||
order2 = 0
|
||||
}
|
||||
private import PrintIRUtilities
|
||||
|
||||
/**
|
||||
* Gets the local dataflow from other nodes in the same function to this node.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Print the dataflow local store steps in IR dumps.
|
||||
*/
|
||||
|
||||
private import cpp
|
||||
// The `ValueNumbering` library has to be imported right after `cpp` to ensure
|
||||
// that the cached IR gets the same checksum here as it does in queries that use
|
||||
// `ValueNumbering` without `DataFlow`.
|
||||
private import semmle.code.cpp.ir.ValueNumbering
|
||||
private import semmle.code.cpp.ir.IR
|
||||
private import semmle.code.cpp.ir.dataflow.DataFlow
|
||||
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
|
||||
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
|
||||
private import PrintIRUtilities
|
||||
|
||||
/**
|
||||
* Property provider for local IR dataflow store steps.
|
||||
*/
|
||||
class LocalFlowPropertyProvider extends IRPropertyProvider {
|
||||
override string getInstructionProperty(Instruction instruction, string key) {
|
||||
exists(DataFlow::Node objectNode, Content content |
|
||||
key = "content[" + content.toString() + "]" and
|
||||
instruction = objectNode.asInstruction() and
|
||||
result =
|
||||
strictconcat(string element, DataFlow::Node fieldNode |
|
||||
storeStep(fieldNode, content, objectNode) and
|
||||
element = nodeId(fieldNode, _, _)
|
||||
|
|
||||
element, ", "
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Shared utilities used when printing dataflow annotations in IR dumps.
|
||||
*/
|
||||
|
||||
private import cpp
|
||||
// The `ValueNumbering` library has to be imported right after `cpp` to ensure
|
||||
// that the cached IR gets the same checksum here as it does in queries that use
|
||||
// `ValueNumbering` without `DataFlow`.
|
||||
private import semmle.code.cpp.ir.ValueNumbering
|
||||
private import semmle.code.cpp.ir.IR
|
||||
private import semmle.code.cpp.ir.dataflow.DataFlow
|
||||
|
||||
/**
|
||||
* Gets a short ID for an IR dataflow node.
|
||||
* - For `Instruction`s, this is just the result ID of the instruction (e.g. `m128`).
|
||||
* - For `Operand`s, this is the label of the operand, prefixed with the result ID of the
|
||||
* instruction and a dot (e.g. `m128.left`).
|
||||
* - For `Variable`s, this is the qualified name of the variable.
|
||||
*/
|
||||
string nodeId(DataFlow::Node node, int order1, int order2) {
|
||||
exists(Instruction instruction | instruction = node.asInstruction() |
|
||||
result = instruction.getResultId() and
|
||||
order1 = instruction.getBlock().getDisplayIndex() and
|
||||
order2 = instruction.getDisplayIndexInBlock()
|
||||
)
|
||||
or
|
||||
exists(Operand operand, Instruction instruction |
|
||||
operand = node.asOperand() and
|
||||
instruction = operand.getUse()
|
||||
|
|
||||
result = instruction.getResultId() + "." + operand.getDumpId() and
|
||||
order1 = instruction.getBlock().getDisplayIndex() and
|
||||
order2 = instruction.getDisplayIndexInBlock()
|
||||
)
|
||||
or
|
||||
result = "var(" + node.asVariable().getQualifiedName() + ")" and
|
||||
order1 = 1000000 and
|
||||
order2 = 0
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Predicates to compute the modeled side effects of calls during IR construction.
|
||||
*
|
||||
* These are used in `TranslatedElement.qll` to generate the `TTranslatedSideEffect` instances, and
|
||||
* also in `TranslatedCall.qll` to inject the actual side effect instructions.
|
||||
*/
|
||||
|
||||
private import cpp
|
||||
private import semmle.code.cpp.ir.implementation.Opcode
|
||||
private import semmle.code.cpp.models.interfaces.SideEffect
|
||||
|
||||
/**
|
||||
* Holds if the specified call has a side effect that does not come from a `SideEffectFunction`
|
||||
* model.
|
||||
*/
|
||||
private predicate hasDefaultSideEffect(Call call, ParameterIndex i, boolean buffer, boolean isWrite) {
|
||||
not call.getTarget() instanceof SideEffectFunction and
|
||||
(
|
||||
exists(MemberFunction mfunc |
|
||||
// A non-static member function, including a constructor or destructor, may write to `*this`,
|
||||
// and may also read from `*this` if it is not a constructor.
|
||||
i = -1 and
|
||||
mfunc = call.getTarget() and
|
||||
not mfunc.isStatic() and
|
||||
buffer = false and
|
||||
(
|
||||
isWrite = false and not mfunc instanceof Constructor
|
||||
or
|
||||
isWrite = true and not mfunc instanceof ConstMemberFunction
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(Expr expr |
|
||||
// A pointer-like argument is assumed to read from the pointed-to buffer, and may write to the
|
||||
// buffer as well unless the pointer points to a `const` value.
|
||||
i >= 0 and
|
||||
buffer = true and
|
||||
expr = call.getArgument(i).getFullyConverted() and
|
||||
exists(Type t | t = expr.getUnspecifiedType() |
|
||||
t instanceof ArrayType or
|
||||
t instanceof PointerType or
|
||||
t instanceof ReferenceType
|
||||
) and
|
||||
(
|
||||
isWrite = true and
|
||||
not call.getTarget().getParameter(i).getType().isDeeplyConstBelow()
|
||||
or
|
||||
isWrite = false
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a side effect opcode for parameter index `i` of the specified call.
|
||||
*
|
||||
* This predicate will return at most two results: one read side effect, and one write side effect.
|
||||
*/
|
||||
Opcode getASideEffectOpcode(Call call, ParameterIndex i) {
|
||||
exists(boolean buffer |
|
||||
(
|
||||
call.getTarget().(SideEffectFunction).hasSpecificReadSideEffect(i, buffer)
|
||||
or
|
||||
not call.getTarget() instanceof SideEffectFunction and
|
||||
hasDefaultSideEffect(call, i, buffer, false)
|
||||
) and
|
||||
if exists(call.getTarget().(SideEffectFunction).getParameterSizeIndex(i))
|
||||
then (
|
||||
buffer = true and
|
||||
result instanceof Opcode::SizedBufferReadSideEffect
|
||||
) else (
|
||||
buffer = false and result instanceof Opcode::IndirectReadSideEffect
|
||||
or
|
||||
buffer = true and result instanceof Opcode::BufferReadSideEffect
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(boolean buffer, boolean mustWrite |
|
||||
(
|
||||
call.getTarget().(SideEffectFunction).hasSpecificWriteSideEffect(i, buffer, mustWrite)
|
||||
or
|
||||
not call.getTarget() instanceof SideEffectFunction and
|
||||
hasDefaultSideEffect(call, i, buffer, true) and
|
||||
mustWrite = false
|
||||
) and
|
||||
if exists(call.getTarget().(SideEffectFunction).getParameterSizeIndex(i))
|
||||
then (
|
||||
buffer = true and
|
||||
mustWrite = false and
|
||||
result instanceof Opcode::SizedBufferMayWriteSideEffect
|
||||
or
|
||||
buffer = true and
|
||||
mustWrite = true and
|
||||
result instanceof Opcode::SizedBufferMustWriteSideEffect
|
||||
) else (
|
||||
buffer = false and
|
||||
mustWrite = false and
|
||||
result instanceof Opcode::IndirectMayWriteSideEffect
|
||||
or
|
||||
buffer = false and
|
||||
mustWrite = true and
|
||||
result instanceof Opcode::IndirectMustWriteSideEffect
|
||||
or
|
||||
buffer = true and mustWrite = false and result instanceof Opcode::BufferMayWriteSideEffect
|
||||
or
|
||||
buffer = true and mustWrite = true and result instanceof Opcode::BufferMustWriteSideEffect
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ private import semmle.code.cpp.ir.implementation.internal.OperandTag
|
||||
private import semmle.code.cpp.ir.internal.CppType
|
||||
private import semmle.code.cpp.models.interfaces.SideEffect
|
||||
private import InstructionTag
|
||||
private import SideEffects
|
||||
private import TranslatedElement
|
||||
private import TranslatedExpr
|
||||
private import TranslatedFunction
|
||||
@@ -424,12 +425,15 @@ class TranslatedCallSideEffects extends TranslatedSideEffects, TTranslatedCallSi
|
||||
}
|
||||
|
||||
class TranslatedStructorCallSideEffects extends TranslatedCallSideEffects {
|
||||
TranslatedStructorCallSideEffects() { getParent().(TranslatedStructorCall).hasQualifier() }
|
||||
TranslatedStructorCallSideEffects() {
|
||||
getParent().(TranslatedStructorCall).hasQualifier() and
|
||||
getASideEffectOpcode(expr, -1) instanceof WriteSideEffectOpcode
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType t) {
|
||||
opcode instanceof Opcode::IndirectMayWriteSideEffect and
|
||||
tag instanceof OnlyInstructionTag and
|
||||
t = getTypeForPRValue(expr.getTarget().getDeclaringType())
|
||||
t = getTypeForPRValue(expr.getTarget().getDeclaringType()) and
|
||||
opcode = getASideEffectOpcode(expr, -1).(WriteSideEffectOpcode)
|
||||
}
|
||||
|
||||
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
@@ -460,9 +464,11 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
|
||||
Call call;
|
||||
Expr arg;
|
||||
int index;
|
||||
boolean write;
|
||||
SideEffectOpcode sideEffectOpcode;
|
||||
|
||||
TranslatedSideEffect() { this = TTranslatedArgumentSideEffect(call, arg, index, write) }
|
||||
TranslatedSideEffect() {
|
||||
this = TTranslatedArgumentSideEffect(call, arg, index, sideEffectOpcode)
|
||||
}
|
||||
|
||||
override Locatable getAST() { result = arg }
|
||||
|
||||
@@ -472,13 +478,13 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
|
||||
|
||||
int getArgumentIndex() { result = index }
|
||||
|
||||
predicate isWrite() { write = true }
|
||||
predicate isWrite() { sideEffectOpcode instanceof WriteSideEffectOpcode }
|
||||
|
||||
override string toString() {
|
||||
write = true and
|
||||
isWrite() and
|
||||
result = "(write side effect for " + arg.toString() + ")"
|
||||
or
|
||||
write = false and
|
||||
not isWrite() and
|
||||
result = "(read side effect for " + arg.toString() + ")"
|
||||
}
|
||||
|
||||
@@ -489,29 +495,29 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
|
||||
override Instruction getFirstInstruction() { result = getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType type) {
|
||||
isWrite() and
|
||||
hasSpecificWriteSideEffect(opcode) and
|
||||
tag = OnlyInstructionTag() and
|
||||
opcode = sideEffectOpcode and
|
||||
(
|
||||
opcode instanceof BufferAccessOpcode and
|
||||
type = getUnknownType()
|
||||
or
|
||||
not opcode instanceof BufferAccessOpcode and
|
||||
exists(Type baseType | baseType = arg.getUnspecifiedType().(DerivedType).getBaseType() |
|
||||
if baseType instanceof VoidType
|
||||
then type = getUnknownType()
|
||||
else type = getTypeForPRValueOrUnknown(baseType)
|
||||
isWrite() and
|
||||
(
|
||||
opcode instanceof BufferAccessOpcode and
|
||||
type = getUnknownType()
|
||||
or
|
||||
not opcode instanceof BufferAccessOpcode and
|
||||
exists(Type baseType | baseType = arg.getUnspecifiedType().(DerivedType).getBaseType() |
|
||||
if baseType instanceof VoidType
|
||||
then type = getUnknownType()
|
||||
else type = getTypeForPRValueOrUnknown(baseType)
|
||||
)
|
||||
or
|
||||
index = -1 and
|
||||
not arg.getUnspecifiedType() instanceof DerivedType and
|
||||
type = getTypeForPRValueOrUnknown(arg.getUnspecifiedType())
|
||||
)
|
||||
or
|
||||
index = -1 and
|
||||
not arg.getUnspecifiedType() instanceof DerivedType and
|
||||
type = getTypeForPRValueOrUnknown(arg.getUnspecifiedType())
|
||||
not isWrite() and
|
||||
type = getVoidType()
|
||||
)
|
||||
or
|
||||
not isWrite() and
|
||||
hasSpecificReadSideEffect(opcode) and
|
||||
tag = OnlyInstructionTag() and
|
||||
type = getVoidType()
|
||||
}
|
||||
|
||||
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
@@ -535,7 +541,7 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
|
||||
|
||||
override CppType getInstructionMemoryOperandType(InstructionTag tag, TypedOperandTag operandTag) {
|
||||
not isWrite() and
|
||||
if hasSpecificReadSideEffect(any(BufferAccessOpcode op))
|
||||
if sideEffectOpcode instanceof BufferAccessOpcode
|
||||
then
|
||||
result = getUnknownType() and
|
||||
tag instanceof OnlyInstructionTag and
|
||||
@@ -557,56 +563,6 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
|
||||
)
|
||||
}
|
||||
|
||||
predicate hasSpecificWriteSideEffect(Opcode op) {
|
||||
exists(boolean buffer, boolean mustWrite |
|
||||
if exists(call.getTarget().(SideEffectFunction).getParameterSizeIndex(index))
|
||||
then
|
||||
call.getTarget().(SideEffectFunction).hasSpecificWriteSideEffect(index, true, mustWrite) and
|
||||
buffer = true and
|
||||
(
|
||||
mustWrite = false and op instanceof Opcode::SizedBufferMayWriteSideEffect
|
||||
or
|
||||
mustWrite = true and op instanceof Opcode::SizedBufferMustWriteSideEffect
|
||||
)
|
||||
else (
|
||||
call.getTarget().(SideEffectFunction).hasSpecificWriteSideEffect(index, buffer, mustWrite) and
|
||||
(
|
||||
buffer = true and mustWrite = false and op instanceof Opcode::BufferMayWriteSideEffect
|
||||
or
|
||||
buffer = false and mustWrite = false and op instanceof Opcode::IndirectMayWriteSideEffect
|
||||
or
|
||||
buffer = true and mustWrite = true and op instanceof Opcode::BufferMustWriteSideEffect
|
||||
or
|
||||
buffer = false and mustWrite = true and op instanceof Opcode::IndirectMustWriteSideEffect
|
||||
)
|
||||
)
|
||||
)
|
||||
or
|
||||
not call.getTarget() instanceof SideEffectFunction and
|
||||
getArgumentIndex() != -1 and
|
||||
op instanceof Opcode::BufferMayWriteSideEffect
|
||||
or
|
||||
not call.getTarget() instanceof SideEffectFunction and
|
||||
getArgumentIndex() = -1 and
|
||||
op instanceof Opcode::IndirectMayWriteSideEffect
|
||||
}
|
||||
|
||||
predicate hasSpecificReadSideEffect(Opcode op) {
|
||||
exists(boolean buffer |
|
||||
call.getTarget().(SideEffectFunction).hasSpecificReadSideEffect(index, buffer) and
|
||||
if exists(call.getTarget().(SideEffectFunction).getParameterSizeIndex(index))
|
||||
then buffer = true and op instanceof Opcode::SizedBufferReadSideEffect
|
||||
else (
|
||||
buffer = true and op instanceof Opcode::BufferReadSideEffect
|
||||
or
|
||||
buffer = false and op instanceof Opcode::IndirectReadSideEffect
|
||||
)
|
||||
)
|
||||
or
|
||||
not call.getTarget() instanceof SideEffectFunction and
|
||||
op instanceof Opcode::BufferReadSideEffect
|
||||
}
|
||||
|
||||
override Instruction getPrimaryInstructionForSideEffect(InstructionTag tag) {
|
||||
tag = OnlyInstructionTag() and
|
||||
result = getTranslatedCallInstruction(call)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user