-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# AddressSanitizer | ||
|
||
[AddressSanitizer (ASan)](https://github.com/google/sanitizers/wiki/AddressSanitizer) - | ||
детектор порчи памяти. Может находить следующие типы ошибок: | ||
|
||
- Heap-, stack-, and global buffer overflow | ||
- Use-after-free (dangling pointer dereference) | ||
- Use-after-scope ```-fsanitize-address-use-after-scope``` | ||
- Use-after-return (pass ```detect_stack_use_after_return=1``` to ```ASAN_OPTIONS```) | ||
- Double free, invalid free | ||
- Initialization order bugs | ||
|
||
ASan приостанавливается на первой обнаруженной ошибке. | ||
Чтобы изменить это поведение нужно добавить флаг компиляции ```-fsanitize-recover=address``` | ||
и ```halt_on_error=false``` в ```ASAN_OPTIONS```. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# --------------------------------------------------------------------------- | ||
# https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
# --------------------------------------------------------------------------- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(global-buffer-overflow) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O1") | ||
|
||
add_executable( | ||
global-buffer-overflow | ||
main.cpp | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
 | ||
|
||
 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int global_array[100] = { -1 }; | ||
|
||
int main(int argc, const char * argv[]) { | ||
return global_array[argc + 100]; // global buffer overflow | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# LeakSanitizer | ||
|
||
[LeakSanitizer (LSan)](https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer) | ||
детектор утечек памяти. В stand-alone режиме это run-time инструмент | ||
не требующий инструментов компиляции. LSan интегрирован в AddressSanitizer | ||
поэтому можно их совместить для обнаружения ошибок памяти и утечек памяти. | ||
|
||
Чтобы включить LeakSanitizer как часть AddressSanitizer нужно передать | ||
```detect_leaks=1``` в переменную ```ASAN_OPTIONS```. Чтобы выключить | ||
```detect_leaks=0```. | ||
|
||
Чтобы запустить только LSan нужно использовать ```-fsanitize=leak``` вместо | ||
```-fsanitize=address```. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# --------------------------------------------------------------------------- | ||
# https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
# --------------------------------------------------------------------------- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(no-del-of-heap-alloc-obj) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak") | ||
|
||
add_executable( | ||
no-del-of-heap-alloc-obj | ||
main.cpp | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
 | ||
|
||
 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int main(int argc, const char * argv[]) { | ||
int *x = new int(10); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# --------------------------------------------------------------------------- | ||
# https://github.com/github/gitignore/blob/master/C.gitignore | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
# --------------------------------------------------------------------------- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Stack Overflow | ||
|
||
- [macos - Mac OS: Leaks Sanitizer](https://stackoverflow.com/a/55778432) | ||
- [Build LLVM / Clang on MacOS](https://gist.github.com/datlife/c754535f18b422f6b8d59028c7f31bac) | ||
|
||
If we are using XCode 10, you will notice that if you navigate to /usr in the | ||
Finder, you will not see a folder called 'include' anymore which is why the | ||
terminal complains of the absence of the header files which is contained inside | ||
the 'include' folder. In this [release statement](https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes), | ||
(you navigate to _/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg_ | ||
and run that package to have the 'include' folder installed). Then you should be | ||
good to go. | ||
|
||
- [c++ - Getting llvm/clang (from brew) working on OSX](https://stackoverflow.com/a/54659928) | ||
- [macos - Can't compile C program on a Mac after upgrade to Mojave](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave/52530212#comment91963866_52509602) | ||
|
||
# Homebrew | ||
|
||
- [Clang can no longer find /usr/include header files? fatal error: 'stdlib.h' file not found](https://discourse.brew.sh/t/clang-can-no-longer-find-usr-include-header-files-fatal-error-stdlib-h-file-not-found/4523/2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
# clang -fsanitize=address -g mleak.c; ASAN_OPTIONS=detect_leaks=1 ./a.out | ||
|
||
# ==11499==AddressSanitizer: detect_leaks is not supported on this platform. | ||
# ./build-and-run.sh: line 3: 11499 Abort trap: 6 ASAN_OPTIONS=detect_leaks=1 ./a.out | ||
|
||
|
||
export PATH="/usr/local/opt/llvm/bin:$PATH" | ||
which clang | ||
|
||
# https://discourse.brew.sh/t/clang-can-no-longer-find-usr-include-header-files-fatal-error-stdlib-h-file-not-found/4523 | ||
# clang -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \ | ||
# -fsanitize=address -g mleak.c \ | ||
# && ASAN_OPTIONS=detect_leaks=1 ./a.out | ||
|
||
clang \ | ||
-fsanitize=address -g mleak.c \ | ||
&& ASAN_OPTIONS=detect_leaks=1 ./a.out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdlib.h> | ||
|
||
void *p; | ||
|
||
int main() { | ||
p = malloc(7); | ||
p = 0; // The memory is leaked here. | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# MemorySanitizer | ||
|
||
[MemorySanitizer (MSan)](https://github.com/google/sanitizers/wiki/MemorySanitizer) | ||
обнаруживает чтения неинициализированной памяти. Ищутся случаи, когда | ||
stack- или heap-allocated память читается перед записью. MSan может также | ||
отслеживать неинициализированные биты в bitfield. | ||
|
||
**MSan доступен только в Clang для Linux x86_64 targets.** | ||
|
||
MSan может отследить происхождение неинициализированного значения в том месте, | ||
где оно было создано, и сообщить эту информацию. | ||
Флаг ```-fsanitize-memory-track-origins``` включает эту функциональность. |