fix macOS crashes in TorManager (invalid SYS_gettid syscall) and bytearray (memcpy block on null pointers)#273
Open
jolavillette wants to merge 3 commits intoRetroShare:masterfrom
Conversation
…array (memcpy block on null pointers)
…ecutable search on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes two critical, distinct bugs that cause RetroShare to crash on macOS during the Tor hidden service generation and initialization processes. Both issues stem from macOS having stricter system-level constraints and memory handling than Linux.
1. Fix SIGABRT in [TorManager.cpp] (Invalid sys-call)
RsTor::instance()usedsyscall(SYS_gettid)to verify it was running on the main thread. However,SYS_gettidis a Linux-only system call that does not exist on macOS (Darwin/XNU). This caused theassert()to fail (getpid() == -1), resulting in a mandatorySIGABRTcrash.std::this_thread::get_id(). The thread ID is now securely cached upon the first invocation and correctly asserts against subsequent calls on all platforms.2. Fix SIGSEGV / Undefined Behavior in [bytearray.h] (Null pointer exceptions)
memcpy,memcmp,strncmp) were being called on empty strings (size() == 0), passingnullptrto these low-level C functions. While Linux glibc silently ignoresmemcpy(nullptr, nullptr, 0), macOS clang/libc++ aggressively flags this as Undefined Behavior and triggers a hard crash.size > 0and!empty()guard clauses before all memory operations within [bytearray.h]. Additionally, patched an off-by-one truncation bug inByteArray::replacethat inadvertently stripped trailing characters.