File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
rust/ql/src/queries/security/CWE-825 Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 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 >> 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 >
You can’t perform that action at this time.
0 commit comments