Bug Summary

File:tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
Warning:line 211, column 10
2nd function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MinidumpTypes.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -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 -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D LLDB_USE_BUILTIN_DEMANGLER -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/. -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/Process/minidump/../Utility -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/source/Plugins/Process/minidump -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
1//===-- MinidumpTypes.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// Project includes
11#include "MinidumpTypes.h"
12
13// Other libraries and framework includes
14// C includes
15// C++ includes
16
17using namespace lldb_private;
18using namespace minidump;
19
20const MinidumpHeader *MinidumpHeader::Parse(llvm::ArrayRef<uint8_t> &data) {
21 const MinidumpHeader *header = nullptr;
22 Status error = consumeObject(data, header);
23
24 const MinidumpHeaderConstants signature =
25 static_cast<const MinidumpHeaderConstants>(
26 static_cast<const uint32_t>(header->signature));
27 const MinidumpHeaderConstants version =
28 static_cast<const MinidumpHeaderConstants>(
29 static_cast<const uint32_t>(header->version) & 0x0000ffff);
30 // the high 16 bits of the version field are implementation specific
31
32 if (error.Fail() || signature != MinidumpHeaderConstants::Signature ||
33 version != MinidumpHeaderConstants::Version)
34 return nullptr;
35
36 // TODO check for max number of streams ?
37 // TODO more sanity checks ?
38
39 return header;
40}
41
42// Minidump string
43llvm::Optional<std::string>
44lldb_private::minidump::parseMinidumpString(llvm::ArrayRef<uint8_t> &data) {
45 std::string result;
46
47 const uint32_t *source_length_ptr;
48 Status error = consumeObject(data, source_length_ptr);
49
50 // Copy non-aligned source_length data into aligned memory.
51 uint32_t source_length;
52 std::memcpy(&source_length, source_length_ptr, sizeof(source_length));
53
54 if (error.Fail() || source_length > data.size() || source_length % 2 != 0)
55 return llvm::None;
56
57 auto source_start = reinterpret_cast<const llvm::UTF16 *>(data.data());
58 // source_length is the length of the string in bytes
59 // we need the length of the string in UTF-16 characters/code points (16 bits
60 // per char)
61 // that's why it's divided by 2
62 const auto source_end = source_start + source_length / 2;
63 // resize to worst case length
64 result.resize(UNI_MAX_UTF8_BYTES_PER_CODE_POINT4 * source_length / 2);
65 auto result_start = reinterpret_cast<llvm::UTF8 *>(&result[0]);
66 const auto result_end = result_start + result.size();
67 llvm::ConvertUTF16toUTF8(&source_start, source_end, &result_start, result_end,
68 llvm::strictConversion);
69 const auto result_size =
70 std::distance(reinterpret_cast<llvm::UTF8 *>(&result[0]), result_start);
71 result.resize(result_size); // shrink to actual length
72
73 return result;
74}
75
76// MinidumpThread
77const MinidumpThread *MinidumpThread::Parse(llvm::ArrayRef<uint8_t> &data) {
78 const MinidumpThread *thread = nullptr;
79 Status error = consumeObject(data, thread);
80 if (error.Fail())
81 return nullptr;
82
83 return thread;
84}
85
86llvm::ArrayRef<MinidumpThread>
87MinidumpThread::ParseThreadList(llvm::ArrayRef<uint8_t> &data) {
88 const llvm::support::ulittle32_t *thread_count;
89 Status error = consumeObject(data, thread_count);
90 if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size())
91 return {};
92
93 return llvm::ArrayRef<MinidumpThread>(
94 reinterpret_cast<const MinidumpThread *>(data.data()), *thread_count);
95}
96
97// MinidumpSystemInfo
98const MinidumpSystemInfo *
99MinidumpSystemInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
100 const MinidumpSystemInfo *system_info;
101 Status error = consumeObject(data, system_info);
102 if (error.Fail())
103 return nullptr;
104
105 return system_info;
106}
107
108// MinidumpMiscInfo
109const MinidumpMiscInfo *MinidumpMiscInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
110 const MinidumpMiscInfo *misc_info;
111 Status error = consumeObject(data, misc_info);
112 if (error.Fail())
113 return nullptr;
114
115 return misc_info;
116}
117
118llvm::Optional<lldb::pid_t> MinidumpMiscInfo::GetPid() const {
119 uint32_t pid_flag =
120 static_cast<const uint32_t>(MinidumpMiscInfoFlags::ProcessID);
121 if (flags1 & pid_flag)
122 return llvm::Optional<lldb::pid_t>(process_id);
123
124 return llvm::None;
125}
126
127// Linux Proc Status
128// it's stored as an ascii string in the file
129llvm::Optional<LinuxProcStatus>
130LinuxProcStatus::Parse(llvm::ArrayRef<uint8_t> &data) {
131 LinuxProcStatus result;
132 result.proc_status =
133 llvm::StringRef(reinterpret_cast<const char *>(data.data()), data.size());
134 data = data.drop_front(data.size());
135
136 llvm::SmallVector<llvm::StringRef, 0> lines;
137 result.proc_status.split(lines, '\n', 42);
138 // /proc/$pid/status has 41 lines, but why not use 42?
139 for (auto line : lines) {
140 if (line.consume_front("Pid:")) {
141 line = line.trim();
142 if (!line.getAsInteger(10, result.pid))
143 return result;
144 }
145 }
146
147 return llvm::None;
148}
149
150lldb::pid_t LinuxProcStatus::GetPid() const { return pid; }
151
152// Module stuff
153const MinidumpModule *MinidumpModule::Parse(llvm::ArrayRef<uint8_t> &data) {
154 const MinidumpModule *module = nullptr;
155 Status error = consumeObject(data, module);
156 if (error.Fail())
157 return nullptr;
158
159 return module;
160}
161
162llvm::ArrayRef<MinidumpModule>
163MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
164
165 const llvm::support::ulittle32_t *modules_count;
166 Status error = consumeObject(data, modules_count);
167 if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size())
168 return {};
169
170 return llvm::ArrayRef<MinidumpModule>(
171 reinterpret_cast<const MinidumpModule *>(data.data()), *modules_count);
172}
173
174// Exception stuff
175const MinidumpExceptionStream *
176MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
177 const MinidumpExceptionStream *exception_stream = nullptr;
178 Status error = consumeObject(data, exception_stream);
179 if (error.Fail())
180 return nullptr;
181
182 return exception_stream;
183}
184
185llvm::ArrayRef<MinidumpMemoryDescriptor>
186MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
187 const llvm::support::ulittle32_t *mem_ranges_count;
188 Status error = consumeObject(data, mem_ranges_count);
189 if (error.Fail() ||
190 *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size())
191 return {};
192
193 return llvm::makeArrayRef(
194 reinterpret_cast<const MinidumpMemoryDescriptor *>(data.data()),
195 *mem_ranges_count);
196}
197
198std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
199MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
200 const llvm::support::ulittle64_t *mem_ranges_count;
201 Status error = consumeObject(data, mem_ranges_count);
202 if (error.Fail() ||
1
Assuming the condition is false
2
Taking false branch
203 *mem_ranges_count * sizeof(MinidumpMemoryDescriptor64) > data.size())
204 return {};
205
206 const llvm::support::ulittle64_t *base_rva;
207 error = consumeObject(data, base_rva);
208 if (error.Fail())
3
Assuming the condition is false
4
Taking false branch
209 return {};
210
211 return std::make_pair(
5
2nd function call argument is an uninitialized value
212 llvm::makeArrayRef(
213 reinterpret_cast<const MinidumpMemoryDescriptor64 *>(data.data()),
214 *mem_ranges_count),
215 *base_rva);
216}
217
218std::vector<const MinidumpMemoryInfo *>
219MinidumpMemoryInfo::ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data) {
220 const MinidumpMemoryInfoListHeader *header;
221 Status error = consumeObject(data, header);
222 if (error.Fail() ||
223 header->size_of_header < sizeof(MinidumpMemoryInfoListHeader) ||
224 header->size_of_entry < sizeof(MinidumpMemoryInfo))
225 return {};
226
227 data = data.drop_front(header->size_of_header -
228 sizeof(MinidumpMemoryInfoListHeader));
229
230 if (header->size_of_entry * header->num_of_entries > data.size())
231 return {};
232
233 std::vector<const MinidumpMemoryInfo *> result;
234 for (uint64_t i = 0; i < header->num_of_entries; ++i) {
235 result.push_back(reinterpret_cast<const MinidumpMemoryInfo *>(
236 data.data() + i * header->size_of_entry));
237 }
238
239 return result;
240}