-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #3580 - tiif:feat/malloc0-non-null-pointer, r=RalfJung
Implement non-null pointer for malloc(0) Use non-null pointer for malloc(0) as mentioned in #3576 to detect leaks and double free of ``malloc(0)`` addresses.
- Loading branch information
Showing
6 changed files
with
74 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
unsafe { | ||
let ptr = libc::malloc(0); | ||
libc::free(ptr); | ||
libc::free(ptr); //~ERROR: dangling | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling | ||
--> $DIR/malloc_zero_double_free.rs:LL:CC | ||
| | ||
LL | libc::free(ptr); | ||
| ^^^^^^^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
help: ALLOC was allocated here: | ||
--> $DIR/malloc_zero_double_free.rs:LL:CC | ||
| | ||
LL | let ptr = libc::malloc(0); | ||
| ^^^^^^^^^^^^^^^ | ||
help: ALLOC was deallocated here: | ||
--> $DIR/malloc_zero_double_free.rs:LL:CC | ||
| | ||
LL | libc::free(ptr); | ||
| ^^^^^^^^^^^^^^^ | ||
= note: BACKTRACE (of the first span): | ||
= note: inside `main` at $DIR/malloc_zero_double_free.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
unsafe { | ||
let _ptr = libc::malloc(0); //~ERROR: memory leak | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: memory leaked: ALLOC (C heap, size: 0, align: 1), allocated here: | ||
--> $DIR/malloc_zero_memory_leak.rs:LL:CC | ||
| | ||
LL | let _ptr = libc::malloc(0); | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: BACKTRACE: | ||
= note: inside `main` at $DIR/malloc_zero_memory_leak.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters