@@ -533,8 +533,13 @@ class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
533
533
case GPRRegSet:
534
534
// On ARM, the CPSR register is also included in the count but it is
535
535
// not included in gpr.r so loop until (count-1).
536
- for (uint32_t i = 0 ; i < (count - 1 ); ++i) {
537
- gpr.r [i] = data.GetU32 (&offset);
536
+
537
+ // Prevent static analysis warnings by explicitly contstraining 'count'
538
+ // to acceptable range. Handle possible underflow of count-1
539
+ if (count > 0 && count <= sizeof (gpr.r ) / sizeof (gpr.r [0 ])) {
540
+ for (uint32_t i = 0 ; i < (count - 1 ); ++i) {
541
+ gpr.r [i] = data.GetU32 (&offset);
542
+ }
538
543
}
539
544
// Save cpsr explicitly.
540
545
gpr.cpsr = data.GetU32 (&offset);
@@ -544,7 +549,7 @@ class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
544
549
break ;
545
550
546
551
case FPURegSet: {
547
- uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats . s [ 0 ] ;
552
+ uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats ;
548
553
const int fpu_reg_buf_size = sizeof (fpu.floats );
549
554
if (data.ExtractBytes (offset, fpu_reg_buf_size, eByteOrderLittle,
550
555
fpu_reg_buf) == fpu_reg_buf_size) {
@@ -4116,8 +4121,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
4116
4121
sym[sym_idx].SetReExportedSymbolName (reexport_name);
4117
4122
set_value = false ;
4118
4123
reexport_shlib_needs_fixup[sym_idx] = reexport_name;
4119
- indirect_symbol_names.insert (
4120
- ConstString (symbol_name + ((symbol_name[0 ] == ' _' ) ? 1 : 0 )));
4124
+ indirect_symbol_names.insert (ConstString (
4125
+ symbol_name +
4126
+ ((symbol_name && (symbol_name[0 ] == ' _' )) ? 1 : 0 )));
4121
4127
} else
4122
4128
type = eSymbolTypeUndefined;
4123
4129
} break ;
@@ -6335,6 +6341,11 @@ static offset_t CreateAllImageInfosPayload(
6335
6341
continue ;
6336
6342
ConstString name = section->GetName ();
6337
6343
segment_vmaddr seg_vmaddr;
6344
+ // This is the uncommon case where strncpy is exactly
6345
+ // the right one, doesn't need to be nul terminated.
6346
+ // The segment name in a Mach-O LC_SEGMENT/LC_SEGMENT_64 is char[16] and
6347
+ // is not guaranteed to be nul-terminated if all 16 characters are
6348
+ // used.
6338
6349
strncpy (seg_vmaddr.segname , name.AsCString (),
6339
6350
sizeof (seg_vmaddr.segname ));
6340
6351
seg_vmaddr.vmaddr = vmaddr;
@@ -6726,8 +6737,10 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
6726
6737
buffer.PutHex32 (sizeof (llvm::MachO::note_command));
6727
6738
char namebuf[16 ];
6728
6739
memset (namebuf, 0 , sizeof (namebuf));
6729
- // this is the uncommon case where strncpy is exactly
6740
+ // This is the uncommon case where strncpy is exactly
6730
6741
// the right one, doesn't need to be nul terminated.
6742
+ // LC_NOTE name field is char[16] and is not guaranteed to be
6743
+ // nul-terminated.
6731
6744
strncpy (namebuf, lcnote->name .c_str (), sizeof (namebuf));
6732
6745
buffer.PutRawBytes (namebuf, sizeof (namebuf));
6733
6746
buffer.PutHex64 (lcnote->payload_file_offset );
@@ -6885,8 +6898,10 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
6885
6898
}
6886
6899
uint32_t imgcount = m_data.GetU32 (&offset);
6887
6900
uint64_t entries_fileoff = m_data.GetU64 (&offset);
6888
- offset += 4 ; // uint32_t entries_size;
6889
- offset += 4 ; // uint32_t unused;
6901
+ /* leaving the following dead code as comments for spec documentation
6902
+ offset += 4; // uint32_t entries_size;
6903
+ offset += 4; // uint32_t unused;
6904
+ */
6890
6905
6891
6906
offset = entries_fileoff;
6892
6907
for (uint32_t i = 0 ; i < imgcount; i++) {
0 commit comments