File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ int * f () {
2
+ int *buff = malloc (SIZE*sizeof (int ));
3
+ do_stuff (buff);
4
+ free (buff);
5
+ int *new_buffer = malloc (SIZE*sizeof (int ));
6
+ free (buff); // BAD: If new_buffer is assigned the same address as buff,
7
+ // the memory allocator will free the new buffer memory region,
8
+ // leading to use-after-free problems and memory corruption.
9
+ return new_buffer;
10
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE qhelp PUBLIC
2
+ "-//Semmle//qhelp//EN"
3
+ "qhelp.dtd">
4
+ <qhelp >
5
+
6
+
7
+ <overview >
8
+ <p >
9
+ Dereferencing a pointer after it has been deallocated may result in memory corruption which can
10
+ lead to security vulnerabilities.
11
+ </p >
12
+
13
+ <include src =" dataFlowWarning.inc.qhelp" />
14
+
15
+ </overview >
16
+ <recommendation >
17
+ <p >
18
+ Ensure that all execution paths deallocate the allocated memory at most once. If possible, reassign
19
+ the pointer to a null value after deallocating it. This will both prevent double-free vulnerabilities, and
20
+ increase the likelihood of the operating system raising a runtime error if the pointer is subsequently
21
+ dereferenced after being deallocated.
22
+ </p >
23
+
24
+ </recommendation >
25
+ <example ><sample src =" DoubleFree.cpp" />
26
+ </example >
27
+ <references >
28
+
29
+ <li >
30
+ OWASP:
31
+ <a href =" https://owasp.org/www-community/vulnerabilities/Doubly_freeing_memory" >Doubly freeing memory</a >.
32
+ </li >
33
+
34
+ </references >
35
+ </qhelp >
You can’t perform that action at this time.
0 commit comments