title | description | ms.date | f1_keywords | helpviewer_keywords | |||
---|---|---|---|---|---|---|---|
Error: strncat-param-overlap |
Source examples and live debug screenshots for strcat parameter overlap errors. |
03/02/2021 |
|
|
Address Sanitizer Error: strncat-param-overlap
Code that moves memory in overlapping buffer can cause hard-to-diagnose errors.
This example shows how AddressSanitizer can catch errors caused by overlapped parameters to CRT functions.
(Based on llvm-project/compiler-rt/test/asan/TestCases/strncat-overlap.cpp.)
// example1.cpp
// strncat-param-overlap error
#include <string.h>
void bad_function() {
char buffer[] = "hello\0XXX";
strncat(buffer, buffer + 1, 3); // BOOM
return;
}
int main(int argc, char **argv) {
bad_function();
return 0;
}
To build and test this example, run these commands in a Visual Studio 2019 version 16.9 or later developer command prompt:
cl example1.cpp /fsanitize=address /Zi
devenv /debugexe example1.exe
:::image type="content" source="media/strcat-param-overlap-example-1.png" alt-text="Screenshot of debugger displaying strncat-param-overlap error in example 1.":::
AddressSanitizer overview
AddressSanitizer known issues
AddressSanitizer build and language reference
AddressSanitizer runtime reference
AddressSanitizer shadow bytes
AddressSanitizer cloud or distributed testing
AddressSanitizer debugger integration
AddressSanitizer error examples