Skip to content

Commit

Permalink
Merge pull request #1766 from embrace-io/fix-null-sid
Browse files Browse the repository at this point in the history
Prevent null session ID crashing ndk processing
  • Loading branch information
fractalwrench authored Dec 19, 2024
2 parents aefef3f + 26832fa commit ba6f189
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ 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) {
logger.trackInternalError(InternalErrorType.NATIVE_HANDLER_INSTALL_FAIL, ex)
}
}

private fun sanitizeSessionId(sid: String?) = sid ?: "null"

private fun checkSignalHandlersOverwritten() {
if (configService.autoDataCaptureBehavior.is3rdPartySigHandlerDetectionEnabled()) {
val culprit = delegate.checkForOverwrittenHandlers()
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ba6f189

Please sign in to comment.