Skip to content

Commit 82815b7

Browse files
authored
asan-top-level: Fix typos, a few phrasing items, fixing page links, and fixing images (#3)
* first batch of changes, and trying to get pictures to show up * picture again * Rest of pictures * fixing example links * fixing all links * extra period
1 parent a4cdd57 commit 82815b7

File tree

1 file changed

+50
-61
lines changed

1 file changed

+50
-61
lines changed

docs/cpp/ASAN/asan-top-level.md

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ helpviewer_keywords: ["ASan","sanitizers","AddressSanitizer","clang_rt.asan","Cl
1010

1111
## Overview
1212

13-
The C & C++ languages are powerful, but can suffer from a class of bugs which affect **program correctness** and **program security**. Starting with Visual Studio 2019 16.9, the Microsoft Visual C++ compiler and IDE, support the Address Sanitizer technology which will light up [hard-to-find bugs](#error-types) with **zero false positives**.
13+
The C & C++ languages are powerful, but can suffer from a class of bugs which affect **program correctness** and **program security**. Starting with Visual Studio 2019 16.9 the Microsoft Visual C++ compiler and IDE support the Address Sanitizer technology which will light up [hard-to-find bugs](#error-types) with **zero false positives**.
1414

15-
Using this flag can reduce your time spent on:
15+
Use this flag to reduce your time spent on:
1616

1717
- Basic correctness
1818
- Cross platform portability
1919
- Security
2020
- Stress testing
2121
- Integrating new code
2222

23-
The Address Sanitizer is a compiler and runtime [introduced by Google](https://www.usenix.org/conference/atc12/technical-sessions/presentation/serebryany). Compiling with `cl -fsanitize=addres` is a powerful alternative to both [/RTC](..\..\build\reference\rtc-run-time-error-checks.md), and [/analyze](../..\code-quality/code-analysis-for-c-cpp-overview.md). It provides run-time bug-finding technologies which directly leverage your existing build systems and existing test assets.
23+
The Address Sanitizer is a compiler and runtime [introduced by Google](https://www.usenix.org/conference/atc12/technical-sessions/presentation/serebryany). Compiling with `-fsanitize=address` is a powerful alternative to both [/RTC](https://docs.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-160), and [/analyze](https://docs.microsoft.com/en-us/cpp/build/reference/analyze-code-analysis?view=msvc-160). It provides run-time bug-finding technologies which directly leverage your existing build systems and existing test assets.
2424

25-
Projects can enable the Address Sanitizer with a project setting, or a single additional compiler switch: **-fanitize=address**. The new flag is compatible with all levels of optimization but it is not compatible with three compilation modes: [edit-and-continue](), [incremental linking](..\..\build\reference\incremental-link-incrementally.md), and [/RTC](..\..\build\reference\rtc-run-time-error-checks.md). Apart from those three modes, all other configurations are supported when targeting x86 and x64.
25+
Projects can enable the Address Sanitizer with a project setting, or a single additional compiler switch: **-fanitize=address**. The new flag is compatible with all levels of optimization and configurations of x86 and x64, with several incompatibilities: [edit-and-continue](https://docs.microsoft.com/en-us/visualstudio/debugger/edit-and-continue-visual-cpp?view=vs-2019), [incremental linking](https://docs.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally?view=msvc-160), and [/RTC](https://docs.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-160).
2626

2727
The Address Sanitizer is integrated with the Visual Studio the project system, CMake system and the IDE.
2828

29-
Using the flag -fsanitize=address, the driver (cl.exe) will link a new library with your executable. This library enables integration with the IDE and it can optionally create a new crash dump file. Setting an environment variable via `set ASAN_SAVE_DUMPS=MyFileName.dmpx`your program can automatically create a new type of crash dump file that will contain extra meta-data for efficient, post-mortem debugging of **precisely diagnosed bugs**. These files facilitate using the Address Sanitizer in:
29+
Microsoft's Address Sanitizer technology enables integration with the Visual Studio IDE and it can optionally create a crash dump file when the sanitizer finds a bug at runtime. Set the `ASAN_SAVE_DUMPS="MyFileName.dmpx"` environment variable prior to running your program, and a crash dump file will be created with extra meta-data for efficient, post-mortem debugging of **precisely diagnosed bugs**. These files facilitate using the Address Sanitizer in:
3030

3131
- On-premise single machine or distributed testing
3232
- Cloud based workflows for testing
@@ -35,13 +35,13 @@ Using the flag -fsanitize=address, the driver (cl.exe) will link a new library w
3535

3636
Simply [**install the Address Sanitizer functionality**]().
3737

38-
After installing, you can build your executables with the `-fsanitize=address`compiler switch using any of the following:
38+
After installing, you can build your executables with the `-fsanitize=address` compiler switch using any of the following:
3939

4040
- Command line
4141
- Visual Studio project system
4242
- Visual Studio CMake integration
4343

44-
You simply run your program normally. This will light up [many types of precisely diagnosed bugs](#errors). These [errors can be reported three (3) ways](#TBD): in the debugger IDE, on the command line or stored in a new type of dump file for precise off-line processing.
44+
Recompile, then simply run your program normally. This will light up [many types of precisely diagnosed bugs](#errors). These [errors can be reported in three ways](#TBD): in the debugger IDE, on the command line or stored in a new type of dump file for precise off-line processing.
4545

4646
### Using the Address Sanitizer
4747

@@ -66,79 +66,68 @@ This article will cover the information needed to enable the three workflows lis
6666
6767
## Using the Address Sanitizer from a Developer Command Prompt
6868

69-
Compile with `-fsanitize=address` to enable Address Sanitizer. The compiler flag `-fsanitize=address` is compatible with all existing C++ or C optimization levels (e.g., /Od, /O1, /O2, /O2 /GL and PGO), works with static and dynamic CRTs (e.g. /MD, /MDd, /MT, /MTd) and can be used to create an .EXE or .DLL. Debug information is required for optimal formatting of call stacks. In this example we explicitly pass `-/Zi`.
69+
Compile with `-fsanitize=address` to enable Address Sanitizer. The compiler flag `-fsanitize=address` is compatible with all existing C++ or C optimization levels (e.g., `/Od`, `/O1`, `/O2`, `/O2 /GL` and `PGO`), works with static and dynamic CRTs (e.g. `/MD`, `/MDd`, `/MT`, `/MTd`) and can be used to create an .EXE or .DLL. Debug information is required for optimal formatting of call stacks. In this example we explicitly pass `/Zi`.
7070

71-
The Address Sanitizer libraries (.lib files) will be linked for you. For more detail, and for guidelines on partitioned build systems, see [building to target the Address Sanitizer runtime.](.\asan-building.md).
71+
The Address Sanitizer libraries (.lib files) will be linked for you. For more detail, and for guidelines on partitioned build systems, see [building to target the Address Sanitizer runtime](./asan-building.md).
7272

7373
### Example - basic global buffer overflow:
7474

75-
7675
```cpp
77-
// main.cpp
76+
// basic-global-overflow.cpp
7877
#include <stdio.h>
79-
8078
int x[100];
81-
8279
int main() {
83-
printf("Hello! \n");
80+
printf("Hello!\n");
8481
x[100] = 5; // Boom!
8582
return 0;
8683
}
8784
```
8885
8986
Using a Developer Command Prompt for VS 2019, compile main.cpp using `-fsanitize=address -Zi`
9087
91-
![basic-global-overflow](src_code\asan-top-level\command-basic-global-overflow.png)
88+
![basic-global-overflow](SRC_CODE/asan-top-level/command-basic-global-overflow.PNG)
9289
9390
Running the resulting **main.exe** at the command line, will result in the formatted error report seen below.
9491
95-
Consider the over layed, red boxes which high light seven (7) key pieces of information:
92+
Consider the overlayed, red boxes which high light seven key pieces of information:
9693
97-
![basic-global-overflow](src_code\asan-top-level\basic-global-overflow.png)
94+
![basic-global-overflow](SRC_CODE/asan-top-level/basic-global-overflow.PNG)
9895
9996
**From top to bottom**
10097
101-
1.) This is a global-buffer-overflow
102-
103-
2.) A write of 4 bytes (32-bits) was outside any user defined variable.
104-
105-
3.) The store took place in function `main()` defined in file `basic-global-overflow.cpp` on line 7.
106-
107-
4.) The variable, named `"x"`, defined in basic-global-overflow.cpp on line 3 starting at column 8
108-
109-
5.) This global variable `"x"` is of size 400 bytes
110-
111-
6.) The exact [shadow byte](.\asan-shadowbytes.md) describing the address targeted by the store had a value of `0xf9`
112-
113-
7.) The shadow byte legend says `0xf9` is an area of padding to the right of `int x[100]`
98+
1. This is a global-buffer-overflow
99+
2. A write of 4 bytes (32-bits) was outside any user defined variable.
100+
3. The store took place in function `main()` defined in file `basic-global-overflow.cpp` on line 7.
101+
4. The variable, named `x`, defined in basic-global-overflow.cpp on line 3 starting at column 8
102+
5. This global variable `x` is of size 400 bytes
103+
6. The exact [shadow byte](./asan-shadowbytes.md) describing the address targeted by the store had a value of `0xf9`
104+
7. The shadow byte legend says `0xf9` is an area of padding to the right of `int x[100]`
114105
115106
**Note:** The function names in the call stack are produced through the [LLVM symbolizer](https://llvm.org/docs/CommandGuide/llvm-symbolizer.html) which is invoked by the runtime upon error.
116107
117108
## Using the Address Sanitizer from Visual Studio
118109
119-
We've integrated the Address Sanitizer with the [Visual Studio IDE](https://docs.microsoft.com/en-us/visualstudio/get-started/visual-studio-ide?view=vs-2019). We simply augment the MSDN section on creating a C++ console application seen in the [quick start guide](https://docs.microsoft.com/en-us/cpp/get-started/tutorial-console-cpp?view=msvc-160&viewFallbackFrom=vs-2019).
120-
121-
You can turn on the Address Sanitizer for an MSBuild project by right-clicking on the project in Solution Explorer, choosing Properties, navigating under C/C++ > General, and changing the **Enable Address Sanitizer**
110+
Address Sanitizer is integrated with the Visual Studio IDE. You can turn on the Address Sanitizer for an MSBuild project by right-clicking on the project in Solution Explorer, choosing Properties, navigating under C/C++ > General, and changing the **Enable Address Sanitizer**
122111
123-
![asan-project-system](.\MEDIA\asan-project-system.PNG)
112+
![asan-project-system](MEDIA/asan-project-system.PNG)
124113
125-
**To build** from the IDE, we ask you to knowingly opt out of [these incompatible flags](.\asan-incompatible-flags.md):
114+
**To build** from the IDE, we ask you to knowingly opt out of [these incompatible flags](.asan-incompatible-flags.md):
126115
127116
- turn OFF [edit and continue](https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-and-disable-edit-and-continue?view=vs-2019)
128117
- turn OFF [runtime checks]( )
129118
- turn OFF [incremental linking]( )
130119
131120
To build and run under the debugger, **hit F5**. The following VS window will result:
132121
133-
![global-overflow-IDE](.\MEDIA\asan-F5-global-buffer-overflow.PNG)
122+
![global-overflow-IDE](MEDIA/asan-F5-global-buffer-overflow.PNG)
134123
135124
## Using the Address Sanitizer from Visual Studio: CMake
136125
137126
To enable ASan for [a CMake project created to target Windows](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-160), do the following:
138127
139128
Open the Configurations dropdown at the top of the IDE and click on Manage Configurations.
140129
141-
![configurations](.\media\asan-cmake-configuration.PNG)
130+
![configurations](MEDIA/asan-cmake-configuration.PNG)
142131
143132
This will open the CMake Project Settings UI, which is saved in a CMakeSettings.json file.
144133
@@ -148,45 +137,45 @@ Add the following property: **“addressSanitizerEnabled”: true**
148137
149138
The following image is of CMakeSettings.json after that change:
150139
151-
![cmake-jason](.\media\asan-cmake-jason.PNG)
140+
![cmake-jason](MEDIA/asan-cmake-jason.PNG)
152141
153142
Save this JSON file with `ctrl-s` then `hit F5`to recompile and run under the debugger.
154143
155144
The following screen shot captures the error from the CMake build.
156145
157-
![cmake-F5-runt](.\MEDIA\asan-cmake-F5-error.PNG)
146+
![cmake-F5-runt](MEDIA/asan-cmake-F5-error.PNG)
158147
159148
## Address Sanitizer crash dumps - cloud and distributed workflows
160149
161150
To produce a new type of dump file which can be viewed in Visual Studio on another machine at a later date:
162151
163-
`set ASAN_SAVE_DUMPS="MyFileName.dmpx"`
152+
set ASAN_SAVE_DUMPS="MyFileName.dmpx"
164153
165154
As of Visual Studio 16.9 will be able to display the **precisely diagnosed error**, stored in MyFileName.dmpx, with your source code.
166155
167-
[This new crash dump functionality](.\asan-offline-address-sanitizer-crash-dumps.md) is an enabler for cloud based workflows and distributed testing.
156+
[This new crash dump functionality](./asan-offline-address-sanitizer-crash-dumps.md) is an enabler for cloud based workflows and distributed testing.
168157
169158
## Error types
170159
171160
The following list of runtime errors can be exposed when you run your binaries compiled Address Sanitizer:
172161
173-
- [stack-use-after-scope](.\examples-stack-use-after-scope.md)
174-
- [stack-buffer-overflow](.\examples-stack-buffer-overflow.md)
175-
- [stack-buffer-underflow](.\examples-stack-buffer-underflow.md)
176-
- [stack-use-after-return](.\examples-stack-use-after-return.md)
177-
- [heap-buffer-overflow](.\examples-heap-buffer-overflow.md)
178-
- [heap-use-after-free](.\examples-heap-use-after-free.md)
179-
- [double-free](.\examples-double-free.md)
180-
- [dynamic-stack-buffer-overflow](.\examples-dynamic-stack-buffer-overflow.md)
181-
- [global-overflow](.\examples-global-overflow.md)
182-
- [calloc-overflow](.\examples-calloc-overflow.md)
183-
- [new-delete-type-mismatch](.\examples-new-delete-type-mismatch.md)
184-
- [memcpy-param-overlap](.\examples-memcpy-param-overlap.md)
185-
- [strcat-param-overlap](.\examples-strcat-param-overlap.md)
186-
- [allocation-size-too-big](.\examples-allocation-size-too-big.md)
187-
- [invalid-aligned-alloc-alignment](.\examples-invalid-aligned-alloc-alignment.md)
188-
- [use-after-poison](.\examples-use-after-poison.md)
189-
- [alloc-dealloc-mismatch](.\examples-alloc-dealloc-mismatch.md)
162+
- [stack-use-after-scope](./examples-stack-use-after-scope.md)
163+
- [stack-buffer-overflow](./examples-stack-buffer-overflow.md)
164+
- [stack-buffer-underflow](./examples-stack-buffer-underflow.md)
165+
- [stack-use-after-return](./examples-stack-use-after-return.md)
166+
- [heap-buffer-overflow](./examples-heap-buffer-overflow.md)
167+
- [heap-use-after-free](./examples-heap-use-after-free.md)
168+
- [double-free](./examples-double-free.md)
169+
- [dynamic-stack-buffer-overflow](./examples-dynamic-stack-buffer-overflow.md)
170+
- [global-overflow](./examples-global-overflow.md)
171+
- [calloc-overflow](./examples-calloc-overflow.md)
172+
- [new-delete-type-mismatch](./examples-new-delete-type-mismatch.md)
173+
- [memcpy-param-overlap](./examples-memcpy-param-overlap.md)
174+
- [strcat-param-overlap](./examples-strcat-param-overlap.md)
175+
- [allocation-size-too-big](./examples-allocation-size-too-big.md)
176+
- [invalid-aligned-alloc-alignment](./examples-invalid-aligned-alloc-alignment.md)
177+
- [use-after-poison](./examples-use-after-poison.md)
178+
- [alloc-dealloc-mismatch](./examples-alloc-dealloc-mismatch.md)
190179
191180
## Differences with Clang 12.0
192181
@@ -204,7 +193,7 @@ We did NOT ship features that could lead to false positives in this first releas
204193
- [Container Overflow](https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow)
205194
- [Pointer Subtraction/Comparison](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html)
206195
207-
See [Building for the Address Sanitizer with MSVC](.\asan-building.md) for further details.
196+
See [Building for the Address Sanitizer with MSVC](./asan-building.md) for further details.
208197
209198
## Existing industry documentation
210199
@@ -218,9 +207,9 @@ This seminal paper on the [Address Sanitizer](https://www.usenix.org/system/file
218207
219208
## See also
220209
221-
- [Building for the Address Sanitizer with Visual Studio](.\asan-building.md)
210+
- [Building for the Address Sanitizer with Visual Studio](./asan-building.md)
222211
223-
- [Address Sanitizer runtime](.\address-sanitizer-runtime.md)
212+
- [Address Sanitizer runtime](./address-sanitizer-runtime.md)
224213
225214
These structure all further details into the tools and the run times they target.
226215

0 commit comments

Comments
 (0)