diff options
| author | Pavel Labath <pavel@labath.sk> | 2025-06-02 09:39:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-02 09:39:56 +0200 |
| commit | e9fad0e91c49ca0f2669989dbad95664cbc9cbf3 (patch) | |
| tree | 334be0ec84d6ca6d6db42f670c01fa2622c4b884 /lldb/source/DataFormatters/FormattersHelpers.cpp | |
| parent | 246d5da7fedb39ba1ad838032f2946535606631d (diff) | |
[lldb] Refactor away UB in SBValue::GetLoadAddress (#141799)
The problem was in calling GetLoadAddress on a value in the error state,
where `ValueObject::GetLoadAddress` could end up accessing the
uninitialized "address type" by-ref return value from `GetAddressOf`.
This probably happened because each function expected the other to
initialize it.
We can guarantee initialization by turning this into a proper return
value.
I've added a test, but it only (reliably) crashes if lldb is built with
ubsan.
Diffstat (limited to 'lldb/source/DataFormatters/FormattersHelpers.cpp')
| -rw-r--r-- | lldb/source/DataFormatters/FormattersHelpers.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lldb/source/DataFormatters/FormattersHelpers.cpp b/lldb/source/DataFormatters/FormattersHelpers.cpp index 5f5541c35262..d7b058d91c4a 100644 --- a/lldb/source/DataFormatters/FormattersHelpers.cpp +++ b/lldb/source/DataFormatters/FormattersHelpers.cpp @@ -113,15 +113,16 @@ lldb_private::formatters::ExtractIndexFromString(const char *item_name) { Address lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) { - lldb::addr_t data_addr = LLDB_INVALID_ADDRESS; - AddressType type; + ValueObject::AddrAndType data_addr; if (valobj.IsPointerType()) - data_addr = valobj.GetPointerValue(&type); + data_addr = valobj.GetPointerValue(); else if (valobj.IsArrayType()) - data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true, &type); - if (data_addr != LLDB_INVALID_ADDRESS && type == eAddressTypeFile) - return Address(data_addr, valobj.GetModule()->GetSectionList()); + data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true); - return data_addr; + if (data_addr.address != LLDB_INVALID_ADDRESS && + data_addr.type == eAddressTypeFile) + return Address(data_addr.address, valobj.GetModule()->GetSectionList()); + + return data_addr.address; } |
