Bug Summary

File:src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
Warning:line 65, column 33
Called C++ object pointer is uninitialized

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name RegisterContextMinidump_x86_64.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/liblldbPluginProcess/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../include -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/obj -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/include -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/source -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/obj/../include/lldb/Plugins -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/liblldbPluginProcess/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp

/usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp

1//===-- RegisterContextMinidump_x86_64.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_64.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 llvm::MutableArrayRef<uint8_t> getDestRegister(uint8_t *context,
20 const RegisterInfo &reg) {
21 auto bytes = reg.mutable_data(context);
22
23 switch (reg.kinds[lldb::eRegisterKindLLDB]) {
24 case lldb_cs_x86_64:
25 case lldb_ds_x86_64:
26 case lldb_es_x86_64:
27 case lldb_fs_x86_64:
28 case lldb_gs_x86_64:
29 case lldb_ss_x86_64:
30 return bytes.take_front(2);
31 break;
32 case lldb_rflags_x86_64:
33 return bytes.take_front(4);
34 break;
35 default:
36 return bytes.take_front(8);
37 break;
38 }
39}
40
41static void writeRegister(const void *reg_src, uint8_t *context,
42 const RegisterInfo &reg) {
43 llvm::MutableArrayRef<uint8_t> reg_dest = getDestRegister(context, reg);
44 memcpy(reg_dest.data(), reg_src, reg_dest.size());
45}
46
47lldb::DataBufferSP lldb_private::minidump::ConvertMinidumpContext_x86_64(
48 llvm::ArrayRef<uint8_t> source_data,
49 RegisterInfoInterface *target_reg_interface) {
50
51 const RegisterInfo *reg_info = target_reg_interface->GetRegisterInfo();
52
53 lldb::DataBufferSP result_context_buf(
54 new DataBufferHeap(target_reg_interface->GetGPRSize(), 0));
55 uint8_t *result_base = result_context_buf->GetBytes();
56
57 if (source_data.size() < sizeof(MinidumpContext_x86_64))
1
Assuming the condition is false
2
Taking false branch
58 return nullptr;
59
60 const MinidumpContext_x86_64 *context;
3
'context' declared without an initial value
61 consumeObject(source_data, context);
4
Calling 'consumeObject<lldb_private::minidump::MinidumpContext_x86_64>'
8
Returning from 'consumeObject<lldb_private::minidump::MinidumpContext_x86_64>'
62
63 const MinidumpContext_x86_64_Flags context_flags =
64 static_cast<MinidumpContext_x86_64_Flags>(
65 static_cast<uint32_t>(context->context_flags));
9
Called C++ object pointer is uninitialized
66 auto x86_64_Flag = MinidumpContext_x86_64_Flags::x86_64_Flag;
67 auto ControlFlag = MinidumpContext_x86_64_Flags::Control;
68 auto IntegerFlag = MinidumpContext_x86_64_Flags::Integer;
69 auto SegmentsFlag = MinidumpContext_x86_64_Flags::Segments;
70
71 if ((context_flags & x86_64_Flag) != x86_64_Flag)
72 return nullptr;
73
74 if ((context_flags & ControlFlag) == ControlFlag) {
75 writeRegister(&context->cs, result_base, reg_info[lldb_cs_x86_64]);
76 writeRegister(&context->ss, result_base, reg_info[lldb_ss_x86_64]);
77 writeRegister(&context->eflags, result_base, reg_info[lldb_rflags_x86_64]);
78 writeRegister(&context->rsp, result_base, reg_info[lldb_rsp_x86_64]);
79 writeRegister(&context->rip, result_base, reg_info[lldb_rip_x86_64]);
80 }
81
82 if ((context_flags & SegmentsFlag) == SegmentsFlag) {
83 writeRegister(&context->ds, result_base, reg_info[lldb_ds_x86_64]);
84 writeRegister(&context->es, result_base, reg_info[lldb_es_x86_64]);
85 writeRegister(&context->fs, result_base, reg_info[lldb_fs_x86_64]);
86 writeRegister(&context->gs, result_base, reg_info[lldb_gs_x86_64]);
87 }
88
89 if ((context_flags & IntegerFlag) == IntegerFlag) {
90 writeRegister(&context->rax, result_base, reg_info[lldb_rax_x86_64]);
91 writeRegister(&context->rcx, result_base, reg_info[lldb_rcx_x86_64]);
92 writeRegister(&context->rdx, result_base, reg_info[lldb_rdx_x86_64]);
93 writeRegister(&context->rbx, result_base, reg_info[lldb_rbx_x86_64]);
94 writeRegister(&context->rbp, result_base, reg_info[lldb_rbp_x86_64]);
95 writeRegister(&context->rsi, result_base, reg_info[lldb_rsi_x86_64]);
96 writeRegister(&context->rdi, result_base, reg_info[lldb_rdi_x86_64]);
97 writeRegister(&context->r8, result_base, reg_info[lldb_r8_x86_64]);
98 writeRegister(&context->r9, result_base, reg_info[lldb_r9_x86_64]);
99 writeRegister(&context->r10, result_base, reg_info[lldb_r10_x86_64]);
100 writeRegister(&context->r11, result_base, reg_info[lldb_r11_x86_64]);
101 writeRegister(&context->r12, result_base, reg_info[lldb_r12_x86_64]);
102 writeRegister(&context->r13, result_base, reg_info[lldb_r13_x86_64]);
103 writeRegister(&context->r14, result_base, reg_info[lldb_r14_x86_64]);
104 writeRegister(&context->r15, result_base, reg_info[lldb_r15_x86_64]);
105 }
106
107 // TODO parse the floating point registers
108
109 return result_context_buf;
110}

/usr/src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/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