FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/cpp/ql/src/Critical/NewFreeMismatch.ql at codeql-cli/v2.19.0 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
997
Pull requests
467
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
NewFreeMismatch.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (36 loc) · 1.18 KB
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
NewFreeMismatch.ql
Copy path
File metadata and controls
39 lines (36 loc) · 1.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @name Mismatching new/free or malloc/delete
* @description An object that was allocated with 'malloc' or 'new' is being freed using a mismatching 'free' or 'delete'.
* @kind problem
* @problem.severity warning
* @security-severity 7.5
* @precision high
* @id cpp/new-free-mismatch
* @tags reliability
* security
* external/cwe/cwe-401
*/
import
NewDelete
/**
* Holds if `allocKind` and `freeKind` indicate corresponding
* types of allocation and free.
*/
predicate
correspondingKinds
(
string
allocKind
,
string
freeKind
)
{
allocKind
=
"malloc"
and
freeKind
=
"free"
or
allocKind
=
"new"
and
freeKind
=
"delete"
}
from
Expr
alloc
,
string
allocKind
,
string
allocKindSimple
,
Expr
free
,
Expr
freed
,
string
freeKind
,
string
freeKindSimple
where
allocReaches
(
freed
,
alloc
,
allocKind
)
and
freeExprOrIndirect
(
free
,
freed
,
freeKind
)
and
allocKindSimple
=
allocKind
.
replaceAll
(
"[]"
,
""
)
and
freeKindSimple
=
freeKind
.
replaceAll
(
"[]"
,
""
)
and
not
correspondingKinds
(
allocKindSimple
,
freeKindSimple
)
select
free
,
"There is a "
+
allocKindSimple
+
"/"
+
freeKindSimple
+
" mismatch between this "
+
freeKind
+
" and the corresponding $@."
,
alloc
,
allocKind
Back
|
FazBrowse Home
|
New Git URL