DynamoRIO / DynamoRIO/drmemory
Function-local static causes unadressable access violation
- Dominant language
- C
- Stars
- 2.7k
- Forks
- 290
- PR merge metrics
- No merged PRs in 30d
Description
```
C:\Users\cmaza\cpp\boost-root\libs\unordered>drmemory -version
Dr. Memory version 2.5.0 -- build 0
```
The following C++ code causes Dr. Memory to exit with an error:
```cpp
struct foo {
bool x_;
int y_;
foo(): x_(true), y_(0) {}
};
foo& tester() {
static foo f;
return f;
}
int main()
{
tester();
}
```
Compiled using:
```
C:\Users\cmaza\cpp\boost-root\libs\unordered>cl /?
Microsoft (R) C/C++ Optimizing Compiler Version 19.32.31332 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\cmaza\cpp\boost-root\libs\unordered>cl /Zi /MTd /EHsc /Oy- /Ob0 /Femyapp.exe tester.cpp
C:\Users\cmaza\cpp\boost-root\libs\unordered>drmemory -batch myapp.exe
~~Dr.M~~ Dr. Memory version 2.5.0
~~Dr.M~~ Running "myapp.exe"
~~Dr.M~~ Using system call file C:\Users\cmaza\AppData\Roaming\Dr. Memory\symcache\syscalls_x64.txt
~~Dr.M~~
~~Dr.M~~ Error #1: UNADDRESSABLE ACCESS: reading 0x0000000000000000-0x0000000000000008 8 byte(s)
~~Dr.M~~ # 0 tester [C:\Users\cmaza\cpp\boost-root\libs\unordered\tester.cpp:9]
~~Dr.M~~ # 1 main [C:\Users\cmaza\cpp\boost-root\libs\unordered\tester.cpp:15]
~~Dr.M~~ Note: @0:00:00.280 in thread 3792
~~Dr.M~~ Note: instruction: mov (%rdx,%rcx,8) -> %rcx
~~Dr.M~~
~~Dr.M~~ Error #2: UNINITIALIZED READ: reading 0x0000001589cfdf5a-0x0000001589cfdf60 6 byte(s) within 0x0000001589cfdf50-0x0000001589cfdf78
~~Dr.M~~ # 0 ntdll.dll!RtlCaptureContext2 +0x410 (0x00007ffc1c4c87a0 )
~~Dr.M~~ # 1 ntdll.dll!RtlUserThreadStart +0x2a (0x00007ffc1c42485b )
~~Dr.M~~ Note: @0:00:00.588 in thread 3792
~~Dr.M~~ Note: instruction: iret %rsp (%rsp) -> %rsp
~~Dr.M~~
~~Dr.M~~ ERRORS FOUND:
~~Dr.M~~ 1 unique, 1 total unaddressable access(es)
~~Dr.M~~ 1 unique, 3 total uninitialized access(es)
~~Dr.M~~ 0 unique, 0 total invalid heap argument(s)
~~Dr.M~~ 0 unique, 0 total GDI usage error(s)
~~Dr.M~~ 0 unique, 0 total handle leak(s)
~~Dr.M~~ 0 unique, 0 total warning(s)
~~Dr.M~~ 0 unique, 0 total, 0 byte(s) of leak(s)
~~Dr.M~~ 0 unique, 0 total, 0 byte(s) of possible leak(s)
~~Dr.M~~ ERRORS IGNORED:
~~Dr.M~~ 2 potential error(s) (suspected false positives)
~~Dr.M~~ (details: C:\Users\cmaza\AppData\Roaming\Dr. Memory\DrMemory-myapp.exe.18600.000\potential_errors.txt)
~~Dr.M~~ 11 unique, 102 total, 21560 byte(s) of still-reachable allocation(s)
~~Dr.M~~ (re-run with "-show_reachable" for details)
~~Dr.M~~ Details: C:\Users\cmaza\AppData\Roaming\Dr. Memory\DrMemory-myapp.exe.18600.000\results.txt
~~Dr.M~~ WARNING: application exited with abnormal code 0xc0000005
```
Pulling this from a function-local static to a global static fixes the issue.
Contributor guide
Assessment
This issue has not been assessed yet.