-
Notifications
You must be signed in to change notification settings - Fork 416
fixed wrong usage of VirtualFree (win32) #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ void* salloc(size_t len) | |
| #ifndef _WIN32 | ||
| free(ptr); | ||
| #else | ||
| VirtualFree((const void*) pre, MEM_RELEASE); | ||
| VirtualFree((const void*) pre, 0, MEM_RELEASE); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
These call sites still cannot compile on Suggested fix `#ifndef` _WIN32
void* ptr = (void*) valloc(len);
`#else`
- pointer r = (pointer) VirtualAlloc(NULL, n * sizeof(T), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+ void* ptr = VirtualAlloc(NULL, len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
`#endif`
@@
`#ifndef` _WIN32
if (mlock((const void*) ptr, len) != 0)
`#else`
- if (VirtualLock((const void*) r, n * sizeof(T)) == 0)
+ if (VirtualLock((const void*) ptr, len) == 0)
`#endif`
@@
`#ifndef` _WIN32
free(ptr);
`#else`
- VirtualFree((const void*) pre, 0, MEM_RELEASE);
+ VirtualFree((const void*) ptr, 0, MEM_RELEASE);
`#endif`
@@
`#else`
- VirtualFree((const void*) pre, 0, MEM_RELEASE);
+ VirtualFree((const void*) ptr, 0, MEM_RELEASE);
`#endif`Also applies to: 119-119 🤖 Prompt for AI Agents |
||
| #endif | ||
|
|
||
| return NULL; | ||
|
|
@@ -116,7 +116,7 @@ void sfree(void* ptr) | |
| #ifndef _WIN32 | ||
| munlock((const void*) ptr, len); | ||
| #else | ||
| VirtualFree((const void*) pre, MEM_RELEASE); | ||
| VirtualFree((const void*) pre, 0, MEM_RELEASE); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '44,125p' src/lib/data_mgr/salloc.cpp
echo '---'
sed -n '160,180p' src/lib/data_mgr/SecureAllocator.hRepository: softhsm/SoftHSMv2 Length of output: 2211 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '--- src/lib/data_mgr/salloc.cpp ---\n'
cat -n src/lib/data_mgr/salloc.cpp | sed -n '1,220p'
printf '\n--- src/lib/data_mgr/SecureAllocator.h ---\n'
cat -n src/lib/data_mgr/SecureAllocator.h | sed -n '1,260p'Repository: softhsm/SoftHSMv2 Length of output: 246 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- src/lib/data_mgr/salloc.cpp ---'
cat -n src/lib/data_mgr/salloc.cpp | sed -n '1,220p'
echo
echo '--- src/lib/data_mgr/SecureAllocator.h ---'
cat -n src/lib/data_mgr/SecureAllocator.h | sed -n '1,260p'Repository: softhsm/SoftHSMv2 Length of output: 11328 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n '\bpre\b|\bVirtualFree\b|\bfree\(ptr\)' src/lib/data_mgr/salloc.cpp src/lib/data_mgr/SecureAllocator.hRepository: softhsm/SoftHSMv2 Length of output: 580 Fix the Windows secure-path cleanup in 🤖 Prompt for AI Agents |
||
| #endif | ||
|
|
||
| #endif // SENSITIVE_NON_PAGED | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '110,190p' src/lib/data_mgr/SecureAllocator.hRepository: softhsm/SoftHSMv2
Length of output: 1853
Remove the
constcast from bothVirtualFreecalls.VirtualFreetakesLPVOID, soVirtualFree((const void*) ...)still mismatches the Win32 signature and breaks Windows builds; passvoid*/LPVOIDinstead.🤖 Prompt for AI Agents