Skip to content

Commit 7ecba71

Browse files
committed
Rust: Add .qhelp.
1 parent 019fcbf commit 7ecba71

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
7+
<p>
8+
Dereferencing an invalid or dangling pointer is undefined behavior. Memory may be corrupted
9+
causing the program to crash or behave incorrectly, in some cases exposing the program to
10+
potential attacks.
11+
</p>
12+
13+
</overview>
14+
<recommendation>
15+
16+
<p>
17+
When dereferencing a pointer in <code>unsafe</code> code, take care that the pointer is valid and
18+
points to the intended data. Code may need to be rearranged or additional checks added to ensure
19+
safety in all circumstances. If possible, rewrite the code using safe Rust types to avoid this
20+
class of problems altogether.
21+
</p>
22+
23+
</recommendation>
24+
<example>
25+
26+
<p>
27+
In the following example, <code>std::ptr::drop_in_place</code> is used to execute the destructor
28+
of an object. However, a pointer to that object is dereferenced later in the program, causing
29+
undefined behavior:
30+
</p>
31+
32+
<sample src="AccessInvalidPointerBad.rs" />
33+
34+
<p>
35+
In this case undefined behavior can be avoided by rearranging the code so that the dereference
36+
comes before the call to <code>std::ptr::drop_in_place</code>:
37+
</p>
38+
39+
<sample src="AccessInvalidPointerGood.rs" />
40+
41+
</example>
42+
<references>
43+
44+
<li>Rust Documentation: <a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html#dangling-pointers">Behavior considered undefined &gt;&gt; Dangling pointers</a>.</li>
45+
<li>Rust Documentation: <a href="https://doc.rust-lang.org/std/ptr/index.html#safety">Module ptr - Safety</a>.</li>
46+
47+
</references>
48+
</qhelp>

0 commit comments

Comments
 (0)