From e63e3f5e024422a6d43969537384cbd499557b26 Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Tue, 17 Nov 2026 10:03:39 -0600 Subject: [PATCH 1/5] build: [SDK-5059] keep OneSignal frames out of tail calls At -O2 a method whose last act is a system call that raises compiles to a bare b, tearing the frame down before the throw. The frame never reaches callStackReturnAddresses, so a crash in SDK code arrives with only host frames and the uncaught-exception handler declines it. Compile the shipping targets with -fno-optimize-sibling-calls, which restores the bl and the frame. This is ObjC only; swiftc accepts -Xllvm -disable-tail-calls but emits identical code, so it is not worth shipping. Co-authored-by: Cursor --- .../OneSignal.xcodeproj/project.pbxproj | 72 +++++++++++-------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 8e8c9bb7a..9a7b3aed0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -5844,7 +5844,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOSCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -5924,7 +5924,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOSCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7204,6 +7204,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_CFLAGS = "$(inherited) -fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLiveActivities; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7278,6 +7279,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = "$(inherited) -fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLiveActivities; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7346,6 +7348,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_CFLAGS = "$(inherited) -fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLiveActivities; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7603,7 +7606,10 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = ( + "-fembed-bitcode", + "-fno-optimize-sibling-calls", + ); OTHER_LDFLAGS = ""; PRODUCT_NAME = OneSignal; SKIP_INSTALL = YES; @@ -7649,7 +7655,7 @@ ); MACH_O_TYPE = mh_dylib; MTL_ENABLE_DEBUG_INFO = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "com.onesignal.OneSignal-Dynamic"; @@ -7807,7 +7813,10 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = ( + "-fembed-bitcode", + "-fno-optimize-sibling-calls", + ); OTHER_LDFLAGS = ""; PRODUCT_NAME = OneSignal; SKIP_INSTALL = YES; @@ -7855,7 +7864,7 @@ MACH_O_TYPE = mh_dylib; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "com.onesignal.OneSignal-Dynamic"; @@ -8013,7 +8022,10 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = ( + "-fembed-bitcode", + "-fno-optimize-sibling-calls", + ); OTHER_LDFLAGS = ""; PRODUCT_NAME = OneSignal; SKIP_INSTALL = YES; @@ -8061,7 +8073,7 @@ MACH_O_TYPE = mh_dylib; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "com.onesignal.OneSignal-Dynamic"; @@ -8275,7 +8287,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; "OTHER_LDFLAGS[sdk=iphoneos*]" = ( "$(inherited)", @@ -8354,7 +8366,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalExtension; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -8418,7 +8430,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOutcomes; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8480,7 +8492,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalUser; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8540,7 +8552,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalUser; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8607,7 +8619,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalUser; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8679,7 +8691,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; "OTHER_LDFLAGS[sdk=iphoneos*]" = ( "$(inherited)", @@ -8771,7 +8783,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; "OTHER_LDFLAGS[sdk=iphoneos*]" = ( "$(inherited)", @@ -8846,7 +8858,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalExtension; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -8913,7 +8925,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalExtension; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -8973,7 +8985,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOutcomes; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9039,7 +9051,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOutcomes; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9245,7 +9257,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLocation; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9313,7 +9325,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLocation; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9375,7 +9387,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLocation; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9435,7 +9447,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalInAppMessages; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9503,7 +9515,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalInAppMessages; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9565,7 +9577,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalInAppMessages; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9638,7 +9650,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOSCore; PRODUCT_NAME = OneSignalOSCore; SKIP_INSTALL = YES; @@ -9801,7 +9813,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalNotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9867,7 +9879,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalNotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9928,7 +9940,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalNotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; From f7fd1a745154bf2b489c5bd4a79f9279934c5c97 Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Tue, 17 Nov 2026 10:03:47 -0600 Subject: [PATCH 2/5] fix: [SDK-5059] stop dropping iOS crashes we cannot attribute The handler only kept a crash when a frame named OneSignal, and treated every other stack as the host's. Three gaps made that unsafe: Most of the ObjC surface uses the OS prefix, not OneSignal, and swizzled categories land on system classes where only the selector names us. Match both halves of an -[Class selector] symbol instead. dladdr cannot see us at all once the SDK is linked into the host executable: release builds strip the local symbols that name our ObjC methods and Swift functions, and a non-nil dli_sname is the nearest exported symbol, which can belong to someone else. Resolve our own image through dladdr at startup and treat attribution as unreliable when it is the main executable, capturing those crashes rather than discarding them. Matching that image also covers wrappers that repackage or rename the frameworks. Record the verdict on CrashData so a crash we could not attribute is visible as ossdk.crash.attributed=false rather than absent, and filter server-side. Tests now drive the installed handler with the addresses a real throw captured, which is the seam the injected-frame tests fell through. Co-authored-by: Cursor --- .../OneSignal.xcodeproj/project.pbxproj | 13 ++ .../Source/Logging/OSLogCrashHandler.swift | 76 ++++++-- .../OSCrashHandlerExceptionRaiser.m | 41 +++++ .../OSLogCrashAttributionTests.swift | 168 ++++++++++++++++++ .../OSLogCrashHandlerTests.swift | 150 ++++++---------- .../OSLoggerAdaptersTests.swift | 3 +- .../OneSignalOSCoreTests-Bridging-Header.h | 17 ++ 7 files changed, 360 insertions(+), 108 deletions(-) create mode 100644 iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m create mode 100644 iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift create mode 100644 iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 9a7b3aed0..9d87d7c51 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -738,6 +738,8 @@ DEFB3E672BB735B500E65DAD /* OSStubLiveActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFB3E662BB735B500E65DAD /* OSStubLiveActivities.swift */; }; ECD9DF65FB98056806A43541 /* OSIdentityVerificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4EAEA1BC62D8FC57927511 /* OSIdentityVerificationService.swift */; }; FD1F1FCA05D555623DD53B54 /* OSUserJwtRepo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8BBA843AFC81A4940CF7CC /* OSUserJwtRepo.swift */; }; + 3C5059A12FD0000000000003 /* OSCrashHandlerExceptionRaiser.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000001 /* OSCrashHandlerExceptionRaiser.m */; }; + 3C5059A12FD0000000000005 /* OSLogCrashAttributionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -2013,6 +2015,9 @@ C3E5A1D7F2B9461EB8D4A6C2 /* ExecutorRequestAgingTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ExecutorRequestAgingTests.swift; sourceTree = ""; }; FF4B19D1EC31C0750F13065A /* OSIamFetchReadyConditionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSIamFetchReadyConditionTests.swift; sourceTree = ""; }; FFBB451F692A15639A1A08AE /* OSOperationRepoIdentityVerificationTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSOperationRepoIdentityVerificationTests.swift; sourceTree = ""; }; + 3C5059A12FD0000000000001 /* OSCrashHandlerExceptionRaiser.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = OSCrashHandlerExceptionRaiser.m; sourceTree = ""; }; + 3C5059A12FD0000000000002 /* OneSignalOSCoreTests-Bridging-Header.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "OneSignalOSCoreTests-Bridging-Header.h"; sourceTree = ""; }; + 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSLogCrashAttributionTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -2786,6 +2791,9 @@ 5B053FB92CAE07EB002F30C4 /* OneSignalOSCoreTests */ = { isa = PBXGroup; children = ( + 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */, + 3C5059A12FD0000000000001 /* OSCrashHandlerExceptionRaiser.m */, + 3C5059A12FD0000000000002 /* OneSignalOSCoreTests-Bridging-Header.h */, 5BC1DE672C90C23E00CA8807 /* OSConsistencyManagerTests.swift */, 3C427AC8301BB28A0059B8B7 /* OSOperationRepoFlushTests.swift */, B5481A0100000000000000A7 /* OSRequestRetryBackoffTests.swift */, @@ -4920,6 +4928,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3C5059A12FD0000000000005 /* OSLogCrashAttributionTests.swift in Sources */, + 3C5059A12FD0000000000003 /* OSCrashHandlerExceptionRaiser.m in Sources */, 5B053FC32CAE0843002F30C4 /* OSConsistencyManagerTests.swift in Sources */, 3C23A21F2FCE0AA1001D32E3 /* OSResilientStorageTests.swift in Sources */, 3C23A21D2FCE0A83001D32E3 /* OSModelStoreRefreshTests.swift in Sources */, @@ -7411,6 +7421,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_OBJC_BRIDGING_HEADER = "OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/UnitTestApp"; @@ -7472,6 +7483,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_OBJC_BRIDGING_HEADER = "OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -7527,6 +7539,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_OBJC_BRIDGING_HEADER = "OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/UnitTestApp"; diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift index a406fb41d..784da4823 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift @@ -27,6 +27,7 @@ import Darwin import Foundation +import MachO import OneSignalCore @_implementationOnly import OneSignalKMP @@ -41,6 +42,35 @@ struct OSResolvedStackFrame: Equatable { let symbolName: String? } +/// The Mach-O image this framework's own code was linked into. +struct OSOwnImage: Equatable { + let path: String? + + /// True once SDK code sits in the host's main executable. Every frame then reports that + /// same image, and the symbol fallback cannot stand in: release builds strip the local + /// symbols that name our ObjC methods and Swift functions, so `dladdr` reports none. + let sharesHostExecutable: Bool + + static let resolved: OSOwnImage = { + var info = Dl_info() + let selfAddress = unsafeBitCast( + osLogUncaughtExceptionHandler as OSExceptionHandler, + to: UnsafeRawPointer.self + ) + guard dladdr(selfAddress, &info) != 0, let ownBase = info.dli_fbase else { + // Keep the narrower behavior: capturing every host crash is a worse failure than + // the drop this guards against, and a lookup inside our own image does not fail. + return OSOwnImage(path: nil, sharesHostExecutable: false) + } + // Image 0 is always the host's main executable. + let mainExecutable = _dyld_get_image_header(0).map { UnsafeRawPointer($0) } + return OSOwnImage( + path: info.dli_fname.map { String(cString: $0) }, + sharesHostExecutable: UnsafeRawPointer(ownBase) == mainExecutable + ) + }() +} + /// Prints KMP diagnostics with `NSLog`, honoring the console log level without going through /// `OneSignalLog` (listeners, alert UI, remote telemetry). Each caller documents why it cannot /// afford that path. @@ -110,11 +140,13 @@ final class OSLogCrashHandler: ILogCrashHandler { private static var inactivePreviousHandler: OSExceptionHandler? private let reporter: ILogCrashReporter + private let ownImage: OSOwnImage private var previousExceptionHandler: OSExceptionHandler? private var isInitialized = false - init(reporter: ILogCrashReporter) { + init(reporter: ILogCrashReporter, ownImage: OSOwnImage = .resolved) { self.reporter = reporter + self.ownImage = ownImage } func initialize() { @@ -165,14 +197,18 @@ final class OSLogCrashHandler: ILogCrashHandler { stackSymbols: [String], resolvedFrames: [OSResolvedStackFrame] ) { - guard Self.isOneSignalAtFault(resolvedFrames) else { + let isAtFault = Self.isOneSignalAtFault(resolvedFrames, ownImagePath: ownImage.path) + // Dropping is only safe where a OneSignal frame would have been recognizable. Where it + // would not, a false negative is indistinguishable from "no crashes happened". + guard isAtFault || ownImage.sharesHostExecutable else { previousExceptionHandler?(exception) return } capture( exceptionType: exception.name.rawValue, exceptionMessage: exception.reason ?? exception.description, - stacktrace: stackSymbols.joined(separator: "\n") + stacktrace: stackSymbols.joined(separator: "\n"), + attributed: isAtFault ) previousExceptionHandler?(exception) } @@ -180,13 +216,15 @@ final class OSLogCrashHandler: ILogCrashHandler { private func capture( exceptionType: String, exceptionMessage: String, - stacktrace: String + stacktrace: String, + attributed: Bool ) { let crash = CrashData( threadName: Self.currentThreadName, exceptionType: exceptionType, exceptionMessage: exceptionMessage, - stacktrace: stacktrace + stacktrace: stacktrace, + attributed: attributed ) do { try reporter.saveCrash(crash: crash) @@ -233,13 +271,18 @@ final class OSLogCrashHandler: ILogCrashHandler { } } - static func isOneSignalAtFault(_ frames: [OSResolvedStackFrame]) -> Bool { + static func isOneSignalAtFault( + _ frames: [OSResolvedStackFrame], + ownImagePath: String? = OSOwnImage.resolved.path + ) -> Bool { frames.contains { frame in guard let imagePath = frame.imagePath, !isSystemImage(imagePath) else { return false } - if oneSignalModules.contains(imageName(from: imagePath)) { + // Matching our own image covers wrappers that repackage or rename the frameworks, + // which the fixed module list cannot see. + if imagePath == ownImagePath || oneSignalModules.contains(imageName(from: imagePath)) { return true } guard let symbolName = frame.symbolName else { @@ -275,10 +318,9 @@ final class OSLogCrashHandler: ILogCrashHandler { private static func isOneSignalSymbol(_ symbol: String) -> Bool { let symbolWithoutLeadingUnderscores = symbol.drop(while: { $0 == "_" }) - if symbolWithoutLeadingUnderscores.hasPrefix("-[OneSignal") - || symbolWithoutLeadingUnderscores.hasPrefix("+[OneSignal") - || symbolWithoutLeadingUnderscores.hasPrefix("onesignal_") - || symbolWithoutLeadingUnderscores.contains("kfun:com.onesignal.") { + if symbolWithoutLeadingUnderscores.hasPrefix("onesignal_") + || symbolWithoutLeadingUnderscores.contains("kfun:com.onesignal.") + || isOneSignalObjCMethod(symbolWithoutLeadingUnderscores) { return true } guard let module = swiftModuleName(from: String(symbolWithoutLeadingUnderscores)) else { @@ -287,6 +329,18 @@ final class OSLogCrashHandler: ILogCrashHandler { return oneSignalModules.contains(module) } + /// Both halves of an `-[Class selector]` symbol can identify us: most of the ObjC surface + /// uses the `OS` prefix rather than `OneSignal`, and swizzled categories land on system + /// classes where only the selector names us (`-[UIApplication setOneSignalDelegate:]`). + private static func isOneSignalObjCMethod(_ symbol: Substring) -> Bool { + guard symbol.hasPrefix("-[") || symbol.hasPrefix("+[") else { + return false + } + let method = symbol.dropFirst(2) + return method.hasPrefix("OS") + || method.range(of: "onesignal", options: .caseInsensitive) != nil + } + private static func swiftModuleName(from symbol: String) -> String? { guard symbol.hasPrefix("$s") else { return nil diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m new file mode 100644 index 000000000..fe3690848 --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m @@ -0,0 +1,41 @@ +/* + Modified MIT License + + Copyright 2026 OneSignal + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + 1. The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 2. All copies of substantial portions of the Software may only be used in connection + with services provided by OneSignal. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +#import "OneSignalOSCoreTests-Bridging-Header.h" + +@implementation OSCrashHandlerExceptionRaiser + ++ (nullable NSException *)exceptionRaisedBy:(void (^)(void))block { + @try { + block(); + } @catch (NSException *exception) { + return exception; + } + return nil; +} + +@end diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift new file mode 100644 index 000000000..be740d82f --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift @@ -0,0 +1,168 @@ +/* + Modified MIT License + + Copyright 2026 OneSignal + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + 1. The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 2. All copies of substantial portions of the Software may only be used in connection + with services provided by OneSignal. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import Foundation +@testable import OneSignalOSCore +import XCTest + +final class OSLogCrashAttributionTests: XCTestCase { + func testIgnoresOneSignalSubstringOutsideModuleField() { + XCTAssertFalse( + isOneSignal([frame(appPath, symbol: "OneSignalNotificationCallback")]) + ) + } + func testRecognizesKnownOneSignalModule() { + XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalNotifications")])) + } + func testRecognizesOneSignalKMPModule() { + XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalKMP")])) + } + func testRecognizesOneSignalCallbackBelowHostThrowingFrame() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "HostCallback"), + dynamicFrame("OneSignalCore", symbol: "OneSignalCallback") + ]) + ) + } + func testRecognizesFoundationOriginatedOneSignalCrash() { + XCTAssertTrue( + isOneSignal([ + frame("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"), + frame("/usr/lib/libobjc.A.dylib"), + frame("/System/Library/Frameworks/Foundation.framework/Foundation"), + dynamicFrame("OneSignalCore") + ]) + ) + } + func testRecognizesStaticFoundationOriginatedOneSignalCrash() { + XCTAssertTrue( + isOneSignal([ + frame("/System/Library/Frameworks/Foundation.framework/Foundation"), + frame(appPath, symbol: "-[OneSignalUserDefaults saveCodeableDataForKey:withValue:]") + ]) + ) + } + func testRecognizesStaticSwiftOneSignalModule() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "_$s13OneSignalUser19OSPropertyOperationC7execute") + ]) + ) + } + func testRecognizesStaticKotlinOneSignalSymbol() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "kfun:com.onesignal.logger.LogCrashReporter.saveCrash") + ]) + ) + } + func testRecognizesStaticNotificationProcessingStack() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "finishProcessingNotification"), + frame(appPath, symbol: "onesignal_Log") + ]) + ) + } + func testRecognizesStaticOSPrefixedObjCClass() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "-[OSNotificationsManager handleNotificationAction:]") + ]) + ) + XCTAssertTrue( + isOneSignal([frame(appPath, symbol: "+[OSMessagingController sharedInstance]")]) + ) + } + func testRecognizesStaticSwizzledCategoryOnSystemClass() { + XCTAssertTrue( + isOneSignal([frame(appPath, symbol: "-[UIApplication setOneSignalDelegate:]")]) + ) + XCTAssertTrue( + isOneSignal([ + frame( + appPath, + symbol: "-[UNUserNotificationCenter onesignalRequestAuthorizationWithOptions:" + + "completionHandler:]" + ) + ]) + ) + } + func testIgnoresUnrelatedObjCMethod() { + XCTAssertFalse( + isOneSignal([frame(appPath, symbol: "-[AppDelegate application:didFinishLaunching:]")]) + ) + } + func testIgnoresGenericOSSymbol() { + XCTAssertFalse(isOneSignal([frame(appPath, symbol: "OSPropertyOperationExecutor")])) + } + + func testIgnoresOneSignalSymbolInSystemImage() { + XCTAssertFalse( + isOneSignal([frame("/usr/lib/libExample.dylib", symbol: "onesignal_Log")]) + ) + } + + func testSkipsSimulatorSystemImage() { + XCTAssertTrue( + isOneSignal([ + frame( + "/Library/Developer/CoreSimulator/Volumes/iOS/RuntimeRoot/" + + "System/Library/Frameworks/Foundation.framework/Foundation", + symbol: "onesignal_Log" + ), + dynamicFrame("OneSignalOSCore") + ]) + ) + } + + func testIgnoresUnresolvedAndEmptyStacks() { + XCTAssertFalse( + isOneSignal([OSResolvedStackFrame(imagePath: nil, symbolName: "onesignal_Log")]) + ) + XCTAssertFalse(isOneSignal([])) + } + + private let appPath = "/private/var/containers/Bundle/Application/App/ExampleApp" + + private func isOneSignal(_ frames: [OSResolvedStackFrame]) -> Bool { + OSLogCrashHandler.isOneSignalAtFault(frames) + } + + private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { + OSResolvedStackFrame(imagePath: imagePath, symbolName: symbol) + } + + private func dynamicFrame(_ module: String, symbol: String? = nil) -> OSResolvedStackFrame { + frame( + "/private/var/containers/Bundle/Application/App/Frameworks/" + + "\(module).framework/\(module)", + symbol: symbol + ) + } +} diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift index 475ef5bf5..7bafa678b 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift @@ -83,118 +83,76 @@ final class OSLogCrashHandlerTests: XCTestCase { XCTAssertTrue(try FileManager.default.contentsOfDirectory(atPath: temporaryDirectory.path).isEmpty) } - private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { - OSResolvedStackFrame(imagePath: imagePath, symbolName: symbol) + /// Drives the installed handler with the addresses the runtime captured at a real throw, so + /// attribution runs on `dladdr` output rather than frames the test supplied. + func testCapturesExceptionThrownThroughOneSignalFrame() throws { + try assertCapture(1, for: raisedThroughOneSignalFrame()) } -} -final class OSLogCrashAttributionTests: XCTestCase { - func testIgnoresOneSignalSubstringOutsideModuleField() { - XCTAssertFalse( - isOneSignal([frame(appPath, symbol: "OneSignalNotificationCallback")]) - ) - } - func testRecognizesKnownOneSignalModule() { - XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalNotifications")])) - } - func testRecognizesOneSignalKMPModule() { - XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalKMP")])) - } - func testRecognizesOneSignalCallbackBelowHostThrowingFrame() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "HostCallback"), - dynamicFrame("OneSignalCore", symbol: "OneSignalCallback") - ]) - ) - } - func testRecognizesFoundationOriginatedOneSignalCrash() { - XCTAssertTrue( - isOneSignal([ - frame("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"), - frame("/usr/lib/libobjc.A.dylib"), - frame("/System/Library/Frameworks/Foundation.framework/Foundation"), - dynamicFrame("OneSignalCore") - ]) - ) - } - func testRecognizesStaticFoundationOriginatedOneSignalCrash() { - XCTAssertTrue( - isOneSignal([ - frame("/System/Library/Frameworks/Foundation.framework/Foundation"), - frame(appPath, symbol: "-[OneSignalUserDefaults saveCodeableDataForKey:withValue:]") - ]) - ) - } - func testRecognizesStaticSwiftOneSignalModule() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "_$s13OneSignalUser19OSPropertyOperationC7execute") - ]) - ) - } - func testRecognizesStaticKotlinOneSignalSymbol() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "kfun:com.onesignal.logger.LogCrashReporter.saveCrash") - ]) - ) - } - func testRecognizesStaticNotificationProcessingStack() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "finishProcessingNotification"), - frame(appPath, symbol: "onesignal_Log") - ]) - ) - } - func testIgnoresGenericOSSymbol() { - XCTAssertFalse(isOneSignal([frame(appPath, symbol: "OSPropertyOperationExecutor")])) + func testIgnoresExceptionThrownEntirelyInHostFrames() throws { + try assertCapture(0, for: raisedInHostFrame()) } - func testIgnoresOneSignalSymbolInSystemImage() { - XCTAssertFalse( - isOneSignal([frame("/usr/lib/libExample.dylib", symbol: "onesignal_Log")]) + /// Where SDK code shares the host executable, no frame can name us, so dropping would hide + /// every one of our crashes behind a stack that looks like the host's. + func testCapturesHostFramesWhenSdkSharesTheHostImage() throws { + try assertCapture( + 1, + for: raisedInHostFrame(), + ownImage: OSOwnImage(path: nil, sharesHostExecutable: true) ) } - func testSkipsSimulatorSystemImage() { - XCTAssertTrue( - isOneSignal([ - frame( - "/Library/Developer/CoreSimulator/Volumes/iOS/RuntimeRoot/" - + "System/Library/Frameworks/Foundation.framework/Foundation", - symbol: "onesignal_Log" - ), - dynamicFrame("OneSignalOSCore") - ]) + /// `OSConsoleLogger` hands `write` a frame inside OneSignalOSCore, which is the only seam + /// here that puts SDK code between the throw and the test bundle. + private func raisedThroughOneSignalFrame() -> NSException? { + let logger = OSConsoleLogger( + consoleLogLevel: { .LL_VERBOSE }, + write: { _ in + NSException(name: NSExceptionName("RaisedException"), reason: "boom").raise() + } ) + return OSCrashHandlerExceptionRaiser.exceptionRaised { logger.error(message: "boom") } } - func testIgnoresUnresolvedAndEmptyStacks() { - XCTAssertFalse( - isOneSignal([OSResolvedStackFrame(imagePath: nil, symbolName: "onesignal_Log")]) - ) - XCTAssertFalse(isOneSignal([])) + private func raisedInHostFrame() -> NSException? { + OSCrashHandlerExceptionRaiser.exceptionRaised { + NSException(name: NSExceptionName("RaisedException"), reason: "boom").raise() + } } - private let appPath = "/private/var/containers/Bundle/Application/App/ExampleApp" + private func assertCapture( + _ expected: Int, + for raised: NSException?, + ownImage: OSOwnImage = .resolved, + file: StaticString = #filePath, + line: UInt = #line + ) throws { + let exception = try XCTUnwrap(raised, file: file, line: line) + XCTAssertFalse(exception.callStackReturnAddresses.isEmpty, file: file, line: line) + + let handler = makeCrashHandler(ownImage: ownImage) + let originalHandler = NSGetUncaughtExceptionHandler() + NSSetUncaughtExceptionHandler(osLogCrashTestExceptionHandler) + defer { NSSetUncaughtExceptionHandler(originalHandler) } + handler.initialize() + defer { handler.unregister() } + + OSLogCrashHandler.handleActive(exception) - private func isOneSignal(_ frames: [OSResolvedStackFrame]) -> Bool { - OSLogCrashHandler.isOneSignalAtFault(frames) + XCTAssertEqual( + try FileManager.default.contentsOfDirectory(atPath: temporaryDirectory.path) + .filter { $0.hasSuffix(".otlp") } + .count, + expected, + file: file, + line: line + ) } private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { OSResolvedStackFrame(imagePath: imagePath, symbolName: symbol) } - - private func dynamicFrame(_ module: String, symbol: String? = nil) -> OSResolvedStackFrame { - frame( - "/private/var/containers/Bundle/Application/App/Frameworks/" - + "\(module).framework/\(module)", - symbol: symbol - ) - } } extension OSLogCrashHandlerTests { @@ -332,7 +290,7 @@ extension OSLogCrashHandlerTests { XCTAssertEqual(started, ["first", "second"]) } - private func makeCrashHandler() -> OSLogCrashHandler { + private func makeCrashHandler(ownImage: OSOwnImage = .resolved) -> OSLogCrashHandler { let store = FileLogStore(rootPath: temporaryDirectory.path) let telemetry = LoggerFactory.shared.createCrashLocalTelemetry( platformProvider: makePlatformProvider(), @@ -342,7 +300,7 @@ extension OSLogCrashHandlerTests { crashTelemetry: telemetry, logger: OSConsoleLogger() ) - return OSLogCrashHandler(reporter: reporter) + return OSLogCrashHandler(reporter: reporter, ownImage: ownImage) } private func makePlatformProvider() -> OSLoggerPlatformProvider { diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift index 3c382a252..98bbde5fd 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift @@ -351,7 +351,8 @@ final class OSLoggerAdaptersTests: XCTestCase { threadName: "test", exceptionType: "TestError", exceptionMessage: "test message", - stacktrace: "test stack" + stacktrace: "test stack", + attributed: true ) _ = try reporter.saveNonFatal(crash: crash) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h new file mode 100644 index 000000000..a8e3aa7d4 --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h @@ -0,0 +1,17 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface OSCrashHandlerExceptionRaiser : NSObject + +/// Returns the exception `block` raised, with the return addresses the runtime captured at the +/// throw. Swift cannot catch an `NSException`, so the `@try` has to live here. ++ (nullable NSException *)exceptionRaisedBy:(void (^)(void))block; + +@end + +NS_ASSUME_NONNULL_END From 4aba246e3e4737c0c0d229f55453015635e963b2 Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Tue, 17 Nov 2026 10:49:24 -0600 Subject: [PATCH 3/5] chore: [SDK-5059] bump OneSignal-KMP-SDK submodule Picks up the ossdk.crash.attributed flag on CrashData. Repoint to the release tag once the KMP change lands. Co-authored-by: Cursor --- OneSignal-KMP-SDK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneSignal-KMP-SDK b/OneSignal-KMP-SDK index b5c7bbeab..afd7b795d 160000 --- a/OneSignal-KMP-SDK +++ b/OneSignal-KMP-SDK @@ -1 +1 @@ -Subproject commit b5c7bbeabfa0fdcae036af4f726ac6e6817d0b0d +Subproject commit afd7b795d2cb02180d0d313012f0dcce342c4d0a From 6e6f7cb1e4321d050b0e7e47dc62597cdab68ea7 Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Tue, 17 Nov 2026 12:59:33 -0600 Subject: [PATCH 4/5] fix: [SDK-5059] keep attribution honest where we share the host image Review of the first pass found the image match and the shared-image gate undoing each other. Statically linked, ownImage.path is the host binary, so every host frame matched it and the crash saved as attributed=true, which is exactly the signal the tag exists to carry. Also: image 0 is not the main executable. Inserted libraries take the low indices, so on a real app launch the executable sits behind libRPAC, libXCTestBundleInject and libMainThreadChecker, and sharesHostExecutable read false. Find it by MH_EXECUTE filetype instead. Restrict the bare OS class prefix to the image we share with the host. Our own frameworks are already covered by the module list and the image path, and dladdr resolves ObjC names in unstripped third-party frameworks, where OS would claim unrelated classes such as Aliyun's -[OSSClient ...]. Tests now model static and dynamic linkage explicitly rather than passing a nil image path, which hid the first bug, and assert the tag through a recording reporter instead of counting files. Co-authored-by: Cursor --- .../OneSignal.xcodeproj/project.pbxproj | 8 +-- .../Source/Logging/OSLogCrashHandler.swift | 49 +++++++++++---- ...ionRaiser.m => CrashTestExceptionRaiser.m} | 2 +- .../OSLogCrashAttributionTests.swift | 58 ++++++++++++++--- .../OSLogCrashHandlerTests.swift | 63 ++++++++++++++----- .../OneSignalOSCoreTests-Bridging-Header.h | 2 +- 6 files changed, 140 insertions(+), 42 deletions(-) rename iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/{OSCrashHandlerExceptionRaiser.m => CrashTestExceptionRaiser.m} (96%) diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 9d87d7c51..ffe36526f 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -738,7 +738,7 @@ DEFB3E672BB735B500E65DAD /* OSStubLiveActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFB3E662BB735B500E65DAD /* OSStubLiveActivities.swift */; }; ECD9DF65FB98056806A43541 /* OSIdentityVerificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4EAEA1BC62D8FC57927511 /* OSIdentityVerificationService.swift */; }; FD1F1FCA05D555623DD53B54 /* OSUserJwtRepo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8BBA843AFC81A4940CF7CC /* OSUserJwtRepo.swift */; }; - 3C5059A12FD0000000000003 /* OSCrashHandlerExceptionRaiser.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000001 /* OSCrashHandlerExceptionRaiser.m */; }; + 3C5059A12FD0000000000003 /* CrashTestExceptionRaiser.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000001 /* CrashTestExceptionRaiser.m */; }; 3C5059A12FD0000000000005 /* OSLogCrashAttributionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */; }; /* End PBXBuildFile section */ @@ -2015,7 +2015,7 @@ C3E5A1D7F2B9461EB8D4A6C2 /* ExecutorRequestAgingTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ExecutorRequestAgingTests.swift; sourceTree = ""; }; FF4B19D1EC31C0750F13065A /* OSIamFetchReadyConditionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSIamFetchReadyConditionTests.swift; sourceTree = ""; }; FFBB451F692A15639A1A08AE /* OSOperationRepoIdentityVerificationTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSOperationRepoIdentityVerificationTests.swift; sourceTree = ""; }; - 3C5059A12FD0000000000001 /* OSCrashHandlerExceptionRaiser.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = OSCrashHandlerExceptionRaiser.m; sourceTree = ""; }; + 3C5059A12FD0000000000001 /* CrashTestExceptionRaiser.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = CrashTestExceptionRaiser.m; sourceTree = ""; }; 3C5059A12FD0000000000002 /* OneSignalOSCoreTests-Bridging-Header.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "OneSignalOSCoreTests-Bridging-Header.h"; sourceTree = ""; }; 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSLogCrashAttributionTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -2792,7 +2792,7 @@ isa = PBXGroup; children = ( 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */, - 3C5059A12FD0000000000001 /* OSCrashHandlerExceptionRaiser.m */, + 3C5059A12FD0000000000001 /* CrashTestExceptionRaiser.m */, 3C5059A12FD0000000000002 /* OneSignalOSCoreTests-Bridging-Header.h */, 5BC1DE672C90C23E00CA8807 /* OSConsistencyManagerTests.swift */, 3C427AC8301BB28A0059B8B7 /* OSOperationRepoFlushTests.swift */, @@ -4929,7 +4929,7 @@ buildActionMask = 2147483647; files = ( 3C5059A12FD0000000000005 /* OSLogCrashAttributionTests.swift in Sources */, - 3C5059A12FD0000000000003 /* OSCrashHandlerExceptionRaiser.m in Sources */, + 3C5059A12FD0000000000003 /* CrashTestExceptionRaiser.m in Sources */, 5B053FC32CAE0843002F30C4 /* OSConsistencyManagerTests.swift in Sources */, 3C23A21F2FCE0AA1001D32E3 /* OSResilientStorageTests.swift in Sources */, 3C23A21D2FCE0A83001D32E3 /* OSModelStoreRefreshTests.swift in Sources */, diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift index 784da4823..142db0d94 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift @@ -62,8 +62,13 @@ struct OSOwnImage: Equatable { // the drop this guards against, and a lookup inside our own image does not fail. return OSOwnImage(path: nil, sharesHostExecutable: false) } - // Image 0 is always the host's main executable. - let mainExecutable = _dyld_get_image_header(0).map { UnsafeRawPointer($0) } + // Find the executable by filetype, not by index. Inserted libraries take the low + // indices: XCTest, Main Thread Checker and the simulator shims all land ahead of it. + let mainExecutable = (0..<_dyld_image_count()) + .lazy + .compactMap { _dyld_get_image_header($0) } + .first { $0.pointee.filetype == UInt32(MH_EXECUTE) } + .map { UnsafeRawPointer($0) } return OSOwnImage( path: info.dli_fname.map { String(cString: $0) }, sharesHostExecutable: UnsafeRawPointer(ownBase) == mainExecutable @@ -197,7 +202,7 @@ final class OSLogCrashHandler: ILogCrashHandler { stackSymbols: [String], resolvedFrames: [OSResolvedStackFrame] ) { - let isAtFault = Self.isOneSignalAtFault(resolvedFrames, ownImagePath: ownImage.path) + let isAtFault = Self.isOneSignalAtFault(resolvedFrames, ownImage: ownImage) // Dropping is only safe where a OneSignal frame would have been recognizable. Where it // would not, a false negative is indistinguishable from "no crashes happened". guard isAtFault || ownImage.sharesHostExecutable else { @@ -273,22 +278,29 @@ final class OSLogCrashHandler: ILogCrashHandler { static func isOneSignalAtFault( _ frames: [OSResolvedStackFrame], - ownImagePath: String? = OSOwnImage.resolved.path + ownImage: OSOwnImage = .resolved ) -> Bool { frames.contains { frame in guard let imagePath = frame.imagePath, !isSystemImage(imagePath) else { return false } - // Matching our own image covers wrappers that repackage or rename the frameworks, - // which the fixed module list cannot see. - if imagePath == ownImagePath || oneSignalModules.contains(imageName(from: imagePath)) { + if oneSignalModules.contains(imageName(from: imagePath)) { + return true + } + let isOwnImage = imagePath == ownImage.path + // Our image identifies us only while it is ours alone. Shared with the host, every + // frame matches it and the attribution tag would always read true. + if isOwnImage, !ownImage.sharesHostExecutable { return true } guard let symbolName = frame.symbolName else { return false } - return isOneSignalSymbol(symbolName) + return isOneSignalSymbol( + symbolName, + allowsClassPrefix: isOwnImage && ownImage.sharesHostExecutable + ) } } @@ -316,11 +328,14 @@ final class OSLogCrashHandler: ILogCrashHandler { path.contains("/System/Library/") || path.contains("/usr/lib/") } - private static func isOneSignalSymbol(_ symbol: String) -> Bool { + private static func isOneSignalSymbol(_ symbol: String, allowsClassPrefix: Bool) -> Bool { let symbolWithoutLeadingUnderscores = symbol.drop(while: { $0 == "_" }) if symbolWithoutLeadingUnderscores.hasPrefix("onesignal_") || symbolWithoutLeadingUnderscores.contains("kfun:com.onesignal.") - || isOneSignalObjCMethod(symbolWithoutLeadingUnderscores) { + || isOneSignalObjCMethod( + symbolWithoutLeadingUnderscores, + allowsClassPrefix: allowsClassPrefix + ) { return true } guard let module = swiftModuleName(from: String(symbolWithoutLeadingUnderscores)) else { @@ -332,13 +347,21 @@ final class OSLogCrashHandler: ILogCrashHandler { /// Both halves of an `-[Class selector]` symbol can identify us: most of the ObjC surface /// uses the `OS` prefix rather than `OneSignal`, and swizzled categories land on system /// classes where only the selector names us (`-[UIApplication setOneSignalDelegate:]`). - private static func isOneSignalObjCMethod(_ symbol: Substring) -> Bool { + /// + /// `allowsClassPrefix` is false outside the image we share with the host, where a bare `OS` + /// would claim unrelated classes such as Aliyun's `-[OSSClient ...]`. + private static func isOneSignalObjCMethod( + _ symbol: Substring, + allowsClassPrefix: Bool + ) -> Bool { guard symbol.hasPrefix("-[") || symbol.hasPrefix("+[") else { return false } let method = symbol.dropFirst(2) - return method.hasPrefix("OS") - || method.range(of: "onesignal", options: .caseInsensitive) != nil + if method.range(of: "onesignal", options: .caseInsensitive) != nil { + return true + } + return allowsClassPrefix && method.hasPrefix("OS") } private static func swiftModuleName(from symbol: String) -> String? { diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/CrashTestExceptionRaiser.m similarity index 96% rename from iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m rename to iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/CrashTestExceptionRaiser.m index fe3690848..10f597e8c 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSCrashHandlerExceptionRaiser.m +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/CrashTestExceptionRaiser.m @@ -27,7 +27,7 @@ of this software and associated documentation files (the "Software"), to deal #import "OneSignalOSCoreTests-Bridging-Header.h" -@implementation OSCrashHandlerExceptionRaiser +@implementation CrashTestExceptionRaiser + (nullable NSException *)exceptionRaisedBy:(void (^)(void))block { @try { diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift index be740d82f..42997309a 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift @@ -141,6 +141,33 @@ final class OSLogCrashAttributionTests: XCTestCase { ) } + /// Our image names us only while it is ours alone. Once it is the host binary every frame + /// matches it, which would tag crashes we cannot attribute as if we had. + func testIgnoresHostFramesWhenSdkSharesTheHostImage() { + XCTAssertFalse(isOneSignal([frame(appPath)])) + } + func testRecognizesRepackagedFrameworkByOwnImage() { + let repackaged = OSOwnImage(path: frameworkPath("VendorWrapper"), sharesHostExecutable: false) + XCTAssertTrue( + isOneSignal([frame(frameworkPath("VendorWrapper"))], ownImage: repackaged) + ) + } + func testIgnoresThirdPartyOSPrefixedClass() { + XCTAssertFalse( + isOneSignal([ + frame(frameworkPath("AliyunOSS"), symbol: "-[OSSClient putObject:]") + ]) + ) + } + func testIgnoresOSPrefixedClassOutsideTheSharedHostImage() { + XCTAssertFalse( + isOneSignal( + [frame(appPath, symbol: "-[OSNotificationsManager handleNotificationAction:]")], + ownImage: dynamicallyLinked + ) + ) + } + func testIgnoresUnresolvedAndEmptyStacks() { XCTAssertFalse( isOneSignal([OSResolvedStackFrame(imagePath: nil, symbolName: "onesignal_Log")]) @@ -148,10 +175,12 @@ final class OSLogCrashAttributionTests: XCTestCase { XCTAssertFalse(isOneSignal([])) } - private let appPath = "/private/var/containers/Bundle/Application/App/ExampleApp" - - private func isOneSignal(_ frames: [OSResolvedStackFrame]) -> Bool { - OSLogCrashHandler.isOneSignalAtFault(frames) + /// Every `appPath` case above models static linking, where our code sits in the host binary. + private func isOneSignal( + _ frames: [OSResolvedStackFrame], + ownImage: OSOwnImage = staticallyLinked + ) -> Bool { + OSLogCrashHandler.isOneSignalAtFault(frames, ownImage: ownImage) } private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { @@ -159,10 +188,21 @@ final class OSLogCrashAttributionTests: XCTestCase { } private func dynamicFrame(_ module: String, symbol: String? = nil) -> OSResolvedStackFrame { - frame( - "/private/var/containers/Bundle/Application/App/Frameworks/" - + "\(module).framework/\(module)", - symbol: symbol - ) + frame(frameworkPath(module), symbol: symbol) } } + +private let appPath = "/private/var/containers/Bundle/Application/App/ExampleApp" + +private func frameworkPath(_ module: String) -> String { + "/private/var/containers/Bundle/Application/App/Frameworks/\(module).framework/\(module)" +} + +/// SDK compiled into the host binary, so no frame's image can tell our code from the app's. +private let staticallyLinked = OSOwnImage(path: appPath, sharesHostExecutable: true) + +/// SDK shipped as its own framework, the shape every current integration uses. +private let dynamicallyLinked = OSOwnImage( + path: frameworkPath("OneSignalOSCore"), + sharesHostExecutable: false +) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift index 7bafa678b..17eeee4bf 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift @@ -94,15 +94,32 @@ final class OSLogCrashHandlerTests: XCTestCase { } /// Where SDK code shares the host executable, no frame can name us, so dropping would hide - /// every one of our crashes behind a stack that looks like the host's. - func testCapturesHostFramesWhenSdkSharesTheHostImage() throws { + /// every one of our crashes behind a stack that looks like the host's. The real image path + /// matters here: matching on it would tag these as ours and defeat the server-side filter. + func testCapturesHostFramesUnattributedWhenSdkSharesTheHostImage() throws { + let reporter = RecordingCrashReporter() try assertCapture( 1, for: raisedInHostFrame(), - ownImage: OSOwnImage(path: nil, sharesHostExecutable: true) + ownImage: OSOwnImage(path: Self.testBundleImagePath, sharesHostExecutable: true), + reporter: reporter ) + + XCTAssertEqual(reporter.saved.map(\.attributed), [false]) } + func testCapturesExceptionThroughOneSignalFrameAsAttributed() throws { + let reporter = RecordingCrashReporter() + try assertCapture(1, for: raisedThroughOneSignalFrame(), reporter: reporter) + + XCTAssertEqual(reporter.saved.map(\.attributed), [true]) + } + + /// The image the raised frames resolve to, standing in for a host binary the SDK was + /// linked into. + private static let testBundleImagePath: String? = + class_getImageName(CrashTestExceptionRaiser.self).map { String(cString: $0) } + /// `OSConsoleLogger` hands `write` a frame inside OneSignalOSCore, which is the only seam /// here that puts SDK code between the throw and the test bundle. private func raisedThroughOneSignalFrame() -> NSException? { @@ -112,11 +129,11 @@ final class OSLogCrashHandlerTests: XCTestCase { NSException(name: NSExceptionName("RaisedException"), reason: "boom").raise() } ) - return OSCrashHandlerExceptionRaiser.exceptionRaised { logger.error(message: "boom") } + return CrashTestExceptionRaiser.exceptionRaised { logger.error(message: "boom") } } private func raisedInHostFrame() -> NSException? { - OSCrashHandlerExceptionRaiser.exceptionRaised { + CrashTestExceptionRaiser.exceptionRaised { NSException(name: NSExceptionName("RaisedException"), reason: "boom").raise() } } @@ -125,13 +142,14 @@ final class OSLogCrashHandlerTests: XCTestCase { _ expected: Int, for raised: NSException?, ownImage: OSOwnImage = .resolved, + reporter: RecordingCrashReporter? = nil, file: StaticString = #filePath, line: UInt = #line ) throws { let exception = try XCTUnwrap(raised, file: file, line: line) XCTAssertFalse(exception.callStackReturnAddresses.isEmpty, file: file, line: line) - let handler = makeCrashHandler(ownImage: ownImage) + let handler = makeCrashHandler(ownImage: ownImage, reporter: reporter) let originalHandler = NSGetUncaughtExceptionHandler() NSSetUncaughtExceptionHandler(osLogCrashTestExceptionHandler) defer { NSSetUncaughtExceptionHandler(originalHandler) } @@ -140,14 +158,11 @@ final class OSLogCrashHandlerTests: XCTestCase { OSLogCrashHandler.handleActive(exception) - XCTAssertEqual( - try FileManager.default.contentsOfDirectory(atPath: temporaryDirectory.path) + let captured = try reporter?.saved.count + ?? FileManager.default.contentsOfDirectory(atPath: temporaryDirectory.path) .filter { $0.hasSuffix(".otlp") } - .count, - expected, - file: file, - line: line - ) + .count + XCTAssertEqual(captured, expected, file: file, line: line) } private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { @@ -290,7 +305,13 @@ extension OSLogCrashHandlerTests { XCTAssertEqual(started, ["first", "second"]) } - private func makeCrashHandler(ownImage: OSOwnImage = .resolved) -> OSLogCrashHandler { + private func makeCrashHandler( + ownImage: OSOwnImage = .resolved, + reporter recording: RecordingCrashReporter? = nil + ) -> OSLogCrashHandler { + if let recording { + return OSLogCrashHandler(reporter: recording, ownImage: ownImage) + } let store = FileLogStore(rootPath: temporaryDirectory.path) let telemetry = LoggerFactory.shared.createCrashLocalTelemetry( platformProvider: makePlatformProvider(), @@ -317,6 +338,20 @@ extension OSLogCrashHandlerTests { } +/// Captures the `CrashData` the handler builds, so tests can read the attribution tag without +/// decoding an OTLP payload. +private final class RecordingCrashReporter: NSObject, ILogCrashReporter { + private(set) var saved: [CrashData] = [] + + func saveCrash(crash: CrashData) throws { + saved.append(crash) + } + + func saveNonFatal(crash: CrashData) throws { + saved.append(crash) + } +} + private typealias TestSignalHandler = @convention(c) (Int32) -> Void private typealias TestExceptionHandler = @convention(c) (NSException) -> Void private let exceptionHandlerCallLock = NSLock() diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h index a8e3aa7d4..579b3b55d 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface OSCrashHandlerExceptionRaiser : NSObject +@interface CrashTestExceptionRaiser : NSObject /// Returns the exception `block` raised, with the return addresses the runtime captured at the /// throw. Swift cannot catch an `NSException`, so the `@try` has to live here. From 692809ae9f986d2d149c21c8f42a01339352bd2a Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Tue, 17 Nov 2026 13:19:45 -0600 Subject: [PATCH 5/5] chore: [SDK-5059] move the KMP submodule pin to the documented CrashData Keeps the pin in step with the PR branch; the change is the exported @property doc and extra test coverage, no behavior. Co-authored-by: Cursor --- OneSignal-KMP-SDK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneSignal-KMP-SDK b/OneSignal-KMP-SDK index afd7b795d..b27ea1f5b 160000 --- a/OneSignal-KMP-SDK +++ b/OneSignal-KMP-SDK @@ -1 +1 @@ -Subproject commit afd7b795d2cb02180d0d313012f0dcce342c4d0a +Subproject commit b27ea1f5b3a7eab850ecc4ff2c34b8924ac75ad2