From 26832fa0ef0aa0b98b0423c5e4e1dd1ee29ec0ef Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Thu, 19 Dec 2024 09:25:49 +0000 Subject: [PATCH] fix: prevent null sid crashing ndk processing --- .../internal/ndk/NativeCrashHandlerInstallerImpl.kt | 8 +++++--- .../android/embracesdk/internal/ndk/jni/JniDelegate.kt | 2 +- .../embracesdk/internal/ndk/jni/JniDelegateImpl.kt | 2 +- .../embrace/android/embracesdk/fakes/FakeJniDelegate.kt | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/NativeCrashHandlerInstallerImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/NativeCrashHandlerInstallerImpl.kt index a6f820b8b1..d029b928c1 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/NativeCrashHandlerInstallerImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/NativeCrashHandlerInstallerImpl.kt @@ -43,14 +43,14 @@ class NativeCrashHandlerInstallerImpl( private fun startNativeCrashMonitoring() { try { if (sharedObjectLoader.loadEmbraceNative()) { - delegate.onSessionChange(sessionIdTracker.getActiveSessionId(), createNativeReportPath()) + delegate.onSessionChange(sanitizeSessionId(sessionIdTracker.getActiveSessionId()), createNativeReportPath()) mainThreadHandler.postAtFrontOfQueue { installSignals() } mainThreadHandler.postDelayed( Runnable(::checkSignalHandlersOverwritten), HANDLER_CHECK_DELAY_MS ) sessionIdTracker.addListener { sessionId -> - delegate.onSessionChange(sessionId, createNativeReportPath()) + delegate.onSessionChange(sanitizeSessionId(sessionId), createNativeReportPath()) } } } catch (ex: Exception) { @@ -58,6 +58,8 @@ class NativeCrashHandlerInstallerImpl( } } + private fun sanitizeSessionId(sid: String?) = sid ?: "null" + private fun checkSignalHandlersOverwritten() { if (configService.autoDataCaptureBehavior.is3rdPartySigHandlerDetectionEnabled()) { val culprit = delegate.checkForOverwrittenHandlers() @@ -100,7 +102,7 @@ class NativeCrashHandlerInstallerImpl( private fun createNativeReportPath(): String { val metadata = StoredTelemetryMetadata( timestamp = clock.now(), - uuid = sessionIdTracker.getActiveSessionId() ?: "null", + uuid = sanitizeSessionId(sessionIdTracker.getActiveSessionId()), processId = processIdProvider(), envelopeType = SupportedEnvelopeType.CRASH, payloadType = PayloadType.NATIVE_CRASH, diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegate.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegate.kt index 9453ddc4b0..99803ceb10 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegate.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegate.kt @@ -10,7 +10,7 @@ interface JniDelegate { devLogging: Boolean, ) fun updateMetaData(metadata: String?) - fun onSessionChange(sessionId: String?, reportPath: String) + fun onSessionChange(sessionId: String, reportPath: String) fun updateAppState(appState: String?) fun getCrashReport(path: String): String? fun checkForOverwrittenHandlers(): String? diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegateImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegateImpl.kt index 3543a3f5bc..a775ec2053 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegateImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/ndk/jni/JniDelegateImpl.kt @@ -11,7 +11,7 @@ class JniDelegateImpl : JniDelegate { ) external override fun updateMetaData(metadata: String?) - external override fun onSessionChange(sessionId: String?, reportPath: String) + external override fun onSessionChange(sessionId: String, reportPath: String) external override fun updateAppState(appState: String?) external override fun getCrashReport(path: String): String? external override fun checkForOverwrittenHandlers(): String? diff --git a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeJniDelegate.kt b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeJniDelegate.kt index d323ae005e..5aefa11caa 100644 --- a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeJniDelegate.kt +++ b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeJniDelegate.kt @@ -25,7 +25,7 @@ class FakeJniDelegate : JniDelegate { // do nothing } - override fun onSessionChange(sessionId: String?, reportPath: String) { + override fun onSessionChange(sessionId: String, reportPath: String) { this.reportPath = reportPath }