Bug Summary

File:build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
Warning:line 42, column 33
Called C++ object pointer is uninitialized

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name RegisterContextMinidump_x86_32.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -isystem /usr/include/libxml2 -D HAVE_ROUND -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/include -I tools/lldb/include -I include -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/include -I /usr/include/python3.9 -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/clang/include -I tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source -I tools/lldb/source -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-09-04-125545-48738-1 -x c++ /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp

/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp

1//===-- RegisterContextMinidump_x86_32.cpp --------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "RegisterContextMinidump_x86_32.h"
10
11#include "lldb/Utility/DataBufferHeap.h"
12
13// C includes
14// C++ includes
15
16using namespace lldb_private;
17using namespace minidump;
18
19static void writeRegister(const void *reg_src,
20 llvm::MutableArrayRef<uint8_t> reg_dest) {
21 memcpy(reg_dest.data(), reg_src, reg_dest.size());
22}
23
24lldb::DataBufferSP lldb_private::minidump::ConvertMinidumpContext_x86_32(
25 llvm::ArrayRef<uint8_t> source_data,
26 RegisterInfoInterface *target_reg_interface) {
27
28 const RegisterInfo *reg_info = target_reg_interface->GetRegisterInfo();
29
30 lldb::WritableDataBufferSP result_context_buf(
31 new DataBufferHeap(target_reg_interface->GetGPRSize(), 0));
32 uint8_t *result_base = result_context_buf->GetBytes();
33
34 if (source_data.size() < sizeof(MinidumpContext_x86_32))
1
Assuming the condition is false
2
Taking false branch
35 return nullptr;
36
37 const MinidumpContext_x86_32 *context;
3
'context' declared without an initial value
38 consumeObject(source_data, context);
4
Calling 'consumeObject<lldb_private::minidump::MinidumpContext_x86_32>'
8
Returning from 'consumeObject<lldb_private::minidump::MinidumpContext_x86_32>'
39
40 const MinidumpContext_x86_32_Flags context_flags =
41 static_cast<MinidumpContext_x86_32_Flags>(
42 static_cast<uint32_t>(context->context_flags));
9
Called C++ object pointer is uninitialized
43 auto x86_32_Flag = MinidumpContext_x86_32_Flags::x86_32_Flag;
44 auto ControlFlag = MinidumpContext_x86_32_Flags::Control;
45 auto IntegerFlag = MinidumpContext_x86_32_Flags::Integer;
46 auto SegmentsFlag = MinidumpContext_x86_32_Flags::Segments;
47
48 if ((context_flags & x86_32_Flag) != x86_32_Flag) {
49 return nullptr;
50 }
51
52 if ((context_flags & ControlFlag) == ControlFlag) {
53 writeRegister(&context->ebp,
54 reg_info[lldb_ebp_i386].mutable_data(result_base));
55 writeRegister(&context->eip,
56 reg_info[lldb_eip_i386].mutable_data(result_base));
57 writeRegister(&context->cs,
58 reg_info[lldb_cs_i386].mutable_data(result_base));
59 writeRegister(&context->eflags,
60 reg_info[lldb_eflags_i386].mutable_data(result_base));
61 writeRegister(&context->esp,
62 reg_info[lldb_esp_i386].mutable_data(result_base));
63 writeRegister(&context->ss,
64 reg_info[lldb_ss_i386].mutable_data(result_base));
65 }
66
67 if ((context_flags & SegmentsFlag) == SegmentsFlag) {
68 writeRegister(&context->ds,
69 reg_info[lldb_ds_i386].mutable_data(result_base));
70 writeRegister(&context->es,
71 reg_info[lldb_es_i386].mutable_data(result_base));
72 writeRegister(&context->fs,
73 reg_info[lldb_fs_i386].mutable_data(result_base));
74 writeRegister(&context->gs,
75 reg_info[lldb_gs_i386].mutable_data(result_base));
76 }
77
78 if ((context_flags & IntegerFlag) == IntegerFlag) {
79 writeRegister(&context->eax,
80 reg_info[lldb_eax_i386].mutable_data(result_base));
81 writeRegister(&context->ecx,
82 reg_info[lldb_ecx_i386].mutable_data(result_base));
83 writeRegister(&context->edx,
84 reg_info[lldb_edx_i386].mutable_data(result_base));
85 writeRegister(&context->ebx,
86 reg_info[lldb_ebx_i386].mutable_data(result_base));
87 writeRegister(&context->esi,
88 reg_info[lldb_esi_i386].mutable_data(result_base));
89 writeRegister(&context->edi,
90 reg_info[lldb_edi_i386].mutable_data(result_base));
91 }
92
93 // TODO parse the floating point registers
94
95 return result_context_buf;
96}

/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/MinidumpTypes.h

1//===-- MinidumpTypes.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
11
12#include "lldb/Utility/Status.h"
13
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/BitmaskEnum.h"
16#include "llvm/ADT/Optional.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/BinaryFormat/Minidump.h"
20#include "llvm/Support/ConvertUTF.h"
21#include "llvm/Support/Endian.h"
22
23// C includes
24// C++ includes
25
26// Reference:
27// https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx
28// https://chromium.googlesource.com/breakpad/breakpad/
29
30namespace lldb_private {
31
32namespace minidump {
33
34using namespace llvm::minidump;
35
36LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()using ::llvm::BitmaskEnumDetail::operator~; using ::llvm::BitmaskEnumDetail
::operator|; using ::llvm::BitmaskEnumDetail::operator&; using
::llvm::BitmaskEnumDetail::operator^; using ::llvm::BitmaskEnumDetail
::operator|=; using ::llvm::BitmaskEnumDetail::operator&=
; using ::llvm::BitmaskEnumDetail::operator^=
;
37
38enum class CvSignature : uint32_t {
39 Pdb70 = 0x53445352, // RSDS
40 ElfBuildId = 0x4270454c, // BpEL (Breakpad/Crashpad minidumps)
41};
42
43enum class MinidumpMiscInfoFlags : uint32_t {
44 ProcessID = (1 << 0),
45 ProcessTimes = (1 << 1),
46 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ ProcessTimes)LLVM_BITMASK_LARGEST_ENUMERATOR = ProcessTimes
47};
48
49template <typename T>
50Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
51 Status error;
52 if (Buffer.size() < sizeof(T)) {
5
Assuming the condition is true
6
Taking true branch
53 error.SetErrorString("Insufficient buffer!");
54 return error;
7
Returning without writing to 'Object'
55 }
56
57 Object = reinterpret_cast<const T *>(Buffer.data());
58 Buffer = Buffer.drop_front(sizeof(T));
59 return error;
60}
61
62struct MinidumpMemoryDescriptor64 {
63 llvm::support::ulittle64_t start_of_memory_range;
64 llvm::support::ulittle64_t data_size;
65
66 static std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
67 ParseMemory64List(llvm::ArrayRef<uint8_t> &data);
68};
69static_assert(sizeof(MinidumpMemoryDescriptor64) == 16,
70 "sizeof MinidumpMemoryDescriptor64 is not correct!");
71
72// TODO misc2, misc3 ?
73// Reference:
74// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680389(v=vs.85).aspx
75struct MinidumpMiscInfo {
76 llvm::support::ulittle32_t size;
77 // flags1 represents what info in the struct is valid
78 llvm::support::ulittle32_t flags1;
79 llvm::support::ulittle32_t process_id;
80 llvm::support::ulittle32_t process_create_time;
81 llvm::support::ulittle32_t process_user_time;
82 llvm::support::ulittle32_t process_kernel_time;
83
84 static const MinidumpMiscInfo *Parse(llvm::ArrayRef<uint8_t> &data);
85
86 llvm::Optional<lldb::pid_t> GetPid() const;
87};
88static_assert(sizeof(MinidumpMiscInfo) == 24,
89 "sizeof MinidumpMiscInfo is not correct!");
90
91// The /proc/pid/status is saved as an ascii string in the file
92class LinuxProcStatus {
93public:
94 llvm::StringRef proc_status;
95 lldb::pid_t pid;
96
97 static llvm::Optional<LinuxProcStatus> Parse(llvm::ArrayRef<uint8_t> &data);
98
99 lldb::pid_t GetPid() const;
100
101private:
102 LinuxProcStatus() = default;
103};
104
105} // namespace minidump
106} // namespace lldb_private
107#endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H