-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct nits from Niko. Add tests for cdylib and staticlib.
- Loading branch information
Showing
7 changed files
with
111 additions
and
4 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,26 @@ | ||
-include ../tools.mk | ||
|
||
# This test builds a shared object, then an executable that links it as a native | ||
# rust library (constrast to an rlib). The shared library and executable both | ||
# are compiled with address sanitizer, and we assert that a fault in the cdylib | ||
# is correctly detected. | ||
|
||
# NOTE the address sanitizer only supports x86_64 linux and macOS | ||
|
||
ifeq ($(TARGET),x86_64-apple-darwin) | ||
ASAN_SUPPORT=$(SANITIZER_SUPPORT) | ||
EXTRA_RUSTFLAG=-C rpath | ||
else | ||
ifeq ($(TARGET),x86_64-unknown-linux-gnu) | ||
ASAN_SUPPORT=$(SANITIZER_SUPPORT) | ||
EXTRA_RUSTFLAG= | ||
endif | ||
endif | ||
|
||
all: | ||
ifeq ($(ASAN_SUPPORT),1) | ||
$(RUSTC) -g -Z sanitizer=address --crate-type cdylib --target $(TARGET) library.rs | ||
$(RUSTC) -g -Z sanitizer=address --crate-type bin --target $(TARGET) -llibrary program.rs | ||
LD_LIBRARY_PATH=$(TMPDIR) $(TMPDIR)/program 2>&1 | grep -q stack-buffer-overflow | ||
endif | ||
|
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 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[no_mangle] | ||
pub extern fn overflow() { | ||
let xs = [0, 1, 2, 3]; | ||
let y = unsafe { *xs.as_ptr().offset(4) }; | ||
} |
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,17 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern { | ||
fn overflow(); | ||
} | ||
|
||
fn main() { | ||
unsafe { overflow() } | ||
} |
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 @@ | ||
-include ../tools.mk | ||
|
||
# This test builds a staticlib, then an executable that links to it. | ||
# The staticlib and executable both are compiled with address sanitizer, | ||
# and we assert that a fault in the staticlib is correctly detected. | ||
|
||
# NOTE the address sanitizer only supports x86_64 linux and macOS | ||
|
||
ifeq ($(TARGET),x86_64-apple-darwin) | ||
ASAN_SUPPORT=$(SANITIZER_SUPPORT) | ||
EXTRA_RUSTFLAG=-C rpath | ||
else | ||
ifeq ($(TARGET),x86_64-unknown-linux-gnu) | ||
ASAN_SUPPORT=$(SANITIZER_SUPPORT) | ||
EXTRA_RUSTFLAG= | ||
endif | ||
endif | ||
|
||
all: | ||
ifeq ($(ASAN_SUPPORT),1) | ||
$(RUSTC) -g -Z sanitizer=address --crate-type staticlib --target $(TARGET) library.rs | ||
$(CC) program.c $(call STATICLIB,library) $(call OUT_EXE,program) -lasan $(EXTRACFLAGS) $(EXTRACXXFLAGS) | ||
LD_LIBRARY_PATH=$(TMPDIR) $(TMPDIR)/program 2>&1 | grep -q stack-buffer-overflow | ||
endif | ||
|
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 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[no_mangle] | ||
pub extern fn overflow() { | ||
let xs = [0, 1, 2, 3]; | ||
let y = unsafe { *xs.as_ptr().offset(4) }; | ||
} |
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,8 @@ | ||
// ignore-license | ||
void overflow(); | ||
|
||
int main() { | ||
overflow(); | ||
return 0; | ||
} | ||
|