You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Buffer overflow in CMarkup::x_TextToDoc when escaping XML special characters. The function incorrectly uses total buffer size instead of remaining space when copying escape sequences.
ASAN Report:
=================================================================
==2223285==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x504000000031 at pc 0x55555563fdf7 bp 0x7fffffffd270 sp 0x7fffffffca28
WRITE of size 32 at 0x504000000031 thread T0
#00x55555563fdf6 in strncpy ??:?
#10x5555556ddb2f in CMarkup::x_TextToDoc[abi:cxx11](charconst*, bool) const /home/user/qualisys_cpp_sdk/Markup.cpp:734
#20x5555556dbc28 in CMarkup::x_SetAttrib(int, charconst*, charconst*) /home/user/qualisys_cpp_sdk/Markup.cpp:655
#30x5555557a2034 in CRTProtocol::SetSkeletonSettings(std::vector<CRTProtocol::SSettingsSkeletonHierarchical, std::allocator<CRTProtocol::SSettingsSkeletonHierarchical> > const&) /home/user/qualisys_cpp_sdk/RTProtocol.cpp:5928
#40x5555556a06c0 in LLVMFuzzerTestOneInput /home/user/qualisys_cpp_sdk/sdk_fuzz.cc:147
#50x555555864349 in ExecuteFilesOnyByOne /home/user/AFLplusplus/utils/aflpp_driver/aflpp_driver.c:255
#60x555555864145 in LLVMFuzzerRunDriver /home/user/AFLplusplus/utils/aflpp_driver/aflpp_driver.c:?
#70x555555863cfd in main /home/user/AFLplusplus/utils/aflpp_driver/aflpp_driver.c:311
#80x7ffff782a1c9 in __libc_start_call_main csu/../sysdeps/x86/libc-start.c:58
#90x7ffff782a28a in __libc_start_main_impl csu/../csu/libc-start.c:360
#100x5555555bc874 in _start ??:?
0x504000000031 is located 0 bytes after 33-byte region [0x504000000010,0x504000000031)
allocated by thread T0 here:
#00x555555695ce1 in operatornew(unsignedlong) ??:?
#10x7ffff7d6870e in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsignedlong, unsignedlong, charconst*, unsignedlong) ??:?
#20x7ffff7d694ff in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace_aux(unsignedlong, unsignedlong, unsignedlong, char) ??:?
#30x5555556dd481 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::resize(unsignedlong) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/basic_string.h:1114
#40x5555556dd481 in CMarkup::GetBuffer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int) const /home/user/qualisys_cpp_sdk/Markup.cpp:1236
#50x5555556dd481 in CMarkup::x_TextToDoc[abi:cxx11](charconst*, bool) const /home/user/qualisys_cpp_sdk/Markup.cpp:716
#60x5555556dbc28 in CMarkup::x_SetAttrib(int, charconst*, charconst*) /home/user/qualisys_cpp_sdk/Markup.cpp:655
#70x5555557a2034 in CRTProtocol::SetSkeletonSettings(std::vector<CRTProtocol::SSettingsSkeletonHierarchical, std::allocator<CRTProtocol::SSettingsSkeletonHierarchical> > const&) /home/user/qualisys_cpp_sdk/RTProtocol.cpp:5928
#80x5555556a06c0 in LLVMFuzzerTestOneInput /home/user/qualisys_cpp_sdk/sdk_fuzz.cc:147
#90x555555864349 in ExecuteFilesOnyByOne /home/user/AFLplusplus/utils/aflpp_driver/aflpp_driver.c:255
SUMMARY: AddressSanitizer: heap-buffer-overflow ??:? in strncpy
Shadow bytes around the buggy address:
0x503ffffffd80: 000000000000000000000000000000000x503ffffffe00: 000000000000000000000000000000000x503ffffffe80: 000000000000000000000000000000000x503fffffff00: 000000000000000000000000000000000x503fffffff80: 00000000000000000000000000000000
=>0x504000000000: fa fa 00000000[01]fa fa fa fa fa fa fa fa fa
0x504000000080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x504000000100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x504000000180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x504000000200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x504000000280: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==2223285==ABORTING
There appears to be an undefined behavior vulnerability in x_TextToDoc through modification of string data returned by c_str(). The GetBuffer function (Ref.) uses const_cast to remove const from the pointer returned by std::string::c_str() and then modifies the underlying character array through this pointer. This violates the C++ standard requirement that "The program shall not modify any of the values stored in the character array" returned by c_str() (Ref.). This undefined behavior can lead to memory corruption, as the character array is not guaranteed to be modifiable and may be shared or read-only depending on the implementation.
Recommendation
Replace unsafe buffer manipulation with proper string handling as:
strncpy was using total buffer size (nDestSize) instead of remaining space
No length check to ensure the replacement text would fit
Not accounting for null termination space
// Instead of manual buffer manipulation:strncpy(&pDest[nLen], pFound, nDestSize);
// Use std::string operations:
std::string result;
result.reserve(strlen(szText) + strlen(szText)/10 + 7); // Pre-allocate spacefor (constchar* p = szText; *p; ++p) {
if (constchar* found = strchr(pFind, *p)) {
result += szaReplace[found - pFind];
} else {
result += *p;
}
}
The text was updated successfully, but these errors were encountered:
Description
NOTE: I was testing Commit 5ddde9ff91565e17d99d9b827e29177e33025975
Buffer overflow in
CMarkup::x_TextToDoc
when escaping XML special characters. The function incorrectly uses total buffer size instead of remaining space when copying escape sequences.Affected Functions
CMarkup::x_TextToDoc
- SourceCRTProtocol::SetSkeletonSettings
Impact
Stack Trace
Detailed stack trace
Additional note:
There appears to be an undefined behavior vulnerability in
x_TextToDoc
through modification of string data returned byc_str()
. TheGetBuffer
function (Ref.) usesconst_cast
to removeconst
from the pointer returned bystd::string::c_str()
and then modifies the underlying character array through this pointer. This violates the C++ standard requirement that "The program shall not modify any of the values stored in the character array" returned byc_str()
(Ref.). This undefined behavior can lead to memory corruption, as the character array is not guaranteed to be modifiable and may be shared or read-only depending on the implementation.Recommendation
Replace unsafe buffer manipulation with proper string handling as:
strncpy
was using total buffer size (nDestSize
) instead of remaining spaceThe text was updated successfully, but these errors were encountered: