Skip to content

Commit 3664ed4

Browse files
author
git apple-llvm automerger
committed
Merge commit 'db9322b2066c' from llvm.org/main into next
2 parents cbab7a3 + db9322b commit 3664ed4

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,13 @@ class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
537537
case GPRRegSet:
538538
// On ARM, the CPSR register is also included in the count but it is
539539
// not included in gpr.r so loop until (count-1).
540-
for (uint32_t i = 0; i < (count - 1); ++i) {
541-
gpr.r[i] = data.GetU32(&offset);
540+
541+
// Prevent static analysis warnings by explicitly contstraining 'count'
542+
// to acceptable range. Handle possible underflow of count-1
543+
if (count > 0 && count <= sizeof(gpr.r) / sizeof(gpr.r[0])) {
544+
for (uint32_t i = 0; i < (count - 1); ++i) {
545+
gpr.r[i] = data.GetU32(&offset);
546+
}
542547
}
543548
// Save cpsr explicitly.
544549
gpr.cpsr = data.GetU32(&offset);
@@ -548,7 +553,7 @@ class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
548553
break;
549554

550555
case FPURegSet: {
551-
uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats.s[0];
556+
uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats;
552557
const int fpu_reg_buf_size = sizeof(fpu.floats);
553558
if (data.ExtractBytes(offset, fpu_reg_buf_size, eByteOrderLittle,
554559
fpu_reg_buf) == fpu_reg_buf_size) {
@@ -4139,8 +4144,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
41394144
sym[sym_idx].SetReExportedSymbolName(reexport_name);
41404145
set_value = false;
41414146
reexport_shlib_needs_fixup[sym_idx] = reexport_name;
4142-
indirect_symbol_names.insert(
4143-
ConstString(symbol_name + ((symbol_name[0] == '_') ? 1 : 0)));
4147+
indirect_symbol_names.insert(ConstString(
4148+
symbol_name +
4149+
((symbol_name && (symbol_name[0] == '_')) ? 1 : 0)));
41444150
} else
41454151
type = eSymbolTypeUndefined;
41464152
} break;
@@ -6366,6 +6372,11 @@ static offset_t CreateAllImageInfosPayload(
63666372
continue;
63676373
ConstString name = section->GetName();
63686374
segment_vmaddr seg_vmaddr;
6375+
// This is the uncommon case where strncpy is exactly
6376+
// the right one, doesn't need to be nul terminated.
6377+
// The segment name in a Mach-O LC_SEGMENT/LC_SEGMENT_64 is char[16] and
6378+
// is not guaranteed to be nul-terminated if all 16 characters are
6379+
// used.
63696380
strncpy(seg_vmaddr.segname, name.AsCString(),
63706381
sizeof(seg_vmaddr.segname));
63716382
seg_vmaddr.vmaddr = vmaddr;
@@ -6757,8 +6768,10 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
67576768
buffer.PutHex32(sizeof(llvm::MachO::note_command));
67586769
char namebuf[16];
67596770
memset(namebuf, 0, sizeof(namebuf));
6760-
// this is the uncommon case where strncpy is exactly
6771+
// This is the uncommon case where strncpy is exactly
67616772
// the right one, doesn't need to be nul terminated.
6773+
// LC_NOTE name field is char[16] and is not guaranteed to be
6774+
// nul-terminated.
67626775
strncpy(namebuf, lcnote->name.c_str(), sizeof(namebuf));
67636776
buffer.PutRawBytes(namebuf, sizeof(namebuf));
67646777
buffer.PutHex64(lcnote->payload_file_offset);
@@ -6934,8 +6947,10 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
69346947
}
69356948
uint32_t imgcount = m_data.GetU32(&offset);
69366949
uint64_t entries_fileoff = m_data.GetU64(&offset);
6937-
offset += 4; // uint32_t entries_size;
6938-
offset += 4; // uint32_t unused;
6950+
/* leaving the following dead code as comments for spec documentation
6951+
offset += 4; // uint32_t entries_size;
6952+
offset += 4; // uint32_t unused;
6953+
*/
69396954

69406955
offset = entries_fileoff;
69416956
for (uint32_t i = 0; i < imgcount; i++) {

0 commit comments

Comments
 (0)