Skip to content

Commit f64296c

Browse files
mujacicaclaude
andcommitted
Fix shared memory corruption and ELF parsing infinite loop
- Move memset inside shm_exists check to avoid corrupting existing shared memory during re-initialization (fixes daemon attach failure) - Add check for zero aligned sizes in ELF note parsing to prevent infinite loop on 32-bit systems with malformed notes Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 71ea60d commit f64296c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/backends/native/minidump/sentry_minidump_linux.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,13 @@ extract_elf_build_id(const char *elf_path, uint8_t *build_id, size_t max_len)
840840
ptr += sizeof(*nhdr);
841841

842842
// Use aligned sizes in bounds check since pointer advances
843-
// by aligned amounts
843+
// by aligned amounts. Also check for zero advancement to
844+
// prevent infinite loop on malformed notes (e.g., overflow
845+
// on 32-bit when n_namesz/n_descsz are near UINT32_MAX)
844846
size_t aligned_namesz = ((nhdr->n_namesz + 3) & ~3);
845847
size_t aligned_descsz = ((nhdr->n_descsz + 3) & ~3);
848+
if (aligned_namesz == 0 && aligned_descsz == 0)
849+
break; // Prevent infinite loop
846850
if (ptr + aligned_namesz + aligned_descsz > end)
847851
break;
848852

src/backends/native/sentry_crash_ipc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ sentry__crash_ipc_init_app(sem_t *init_sem)
118118
return NULL;
119119
}
120120

121-
// Zero out shared memory to ensure clean state
122-
memset(ipc->shmem, 0, SENTRY_CRASH_SHM_SIZE);
121+
// Zero out shared memory only when first created to ensure clean state
122+
// Don't zero existing memory to avoid corrupting state set by other threads
123+
if (!shm_exists) {
124+
memset(ipc->shmem, 0, SENTRY_CRASH_SHM_SIZE);
125+
}
123126

124127
// Create eventfd for crash notifications
125128
ipc->notify_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);

0 commit comments

Comments
 (0)