@@ -537,8 +537,13 @@ class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
537
537
case GPRRegSet:
538
538
// On ARM, the CPSR register is also included in the count but it is
539
539
// 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
+ }
542
547
}
543
548
// Save cpsr explicitly.
544
549
gpr.cpsr = data.GetU32 (&offset);
@@ -548,7 +553,7 @@ class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
548
553
break ;
549
554
550
555
case FPURegSet: {
551
- uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats . s [ 0 ] ;
556
+ uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats ;
552
557
const int fpu_reg_buf_size = sizeof (fpu.floats );
553
558
if (data.ExtractBytes (offset, fpu_reg_buf_size, eByteOrderLittle,
554
559
fpu_reg_buf) == fpu_reg_buf_size) {
@@ -4139,8 +4144,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
4139
4144
sym[sym_idx].SetReExportedSymbolName (reexport_name);
4140
4145
set_value = false ;
4141
4146
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 )));
4144
4150
} else
4145
4151
type = eSymbolTypeUndefined;
4146
4152
} break ;
@@ -6366,6 +6372,11 @@ static offset_t CreateAllImageInfosPayload(
6366
6372
continue ;
6367
6373
ConstString name = section->GetName ();
6368
6374
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.
6369
6380
strncpy (seg_vmaddr.segname , name.AsCString (),
6370
6381
sizeof (seg_vmaddr.segname ));
6371
6382
seg_vmaddr.vmaddr = vmaddr;
@@ -6757,8 +6768,10 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
6757
6768
buffer.PutHex32 (sizeof (llvm::MachO::note_command));
6758
6769
char namebuf[16 ];
6759
6770
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
6761
6772
// 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.
6762
6775
strncpy (namebuf, lcnote->name .c_str (), sizeof (namebuf));
6763
6776
buffer.PutRawBytes (namebuf, sizeof (namebuf));
6764
6777
buffer.PutHex64 (lcnote->payload_file_offset );
@@ -6934,8 +6947,10 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
6934
6947
}
6935
6948
uint32_t imgcount = m_data.GetU32 (&offset);
6936
6949
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
+ */
6939
6954
6940
6955
offset = entries_fileoff;
6941
6956
for (uint32_t i = 0 ; i < imgcount; i++) {
0 commit comments