fix(device): Keep a log line for rejected malformed addresses

Structurally broken addresses now fail the octet parse instead of
throwing, so the catch-all error log no longer fires for them. Log the
rejection at WARN with a redacted address so support logs still show it.

Fixes review finding F1.
This commit is contained in:
darken
2026-08-31 15:54:51 +02:00
committed by Matthias Urhahn
parent 7712b18388
commit 92dac661c4
2 changed files with 34 additions and 1 deletions
@@ -30,7 +30,12 @@ class RPAChecker @Inject constructor() {
fun resolve(address: BluetoothAddress, irk: IdentityResolvingKey): AddressOrder? = try {
val octets = address.parseOctets()
when {
octets == null -> null
octets == null -> {
log(TAG, Logging.Priority.WARN) {
"Failed to resolve RPA, malformed address: ${address.redactedForLogs()}"
}
null
}
matchesHash(octets, irk) -> AddressOrder.STANDARD
else -> octets.reversedArray()
.takeIf { it.isRpaShaped() && matchesHash(it, irk) }
@@ -162,4 +162,32 @@ class RPACheckerTest : BaseTest() {
captured.any { (_, message) -> message.contains(keyHex, ignoreCase = true) } shouldBe false
captured.any { (_, message) -> message.contains(resolvingAddress) } shouldBe false
}
@Test
fun `a malformed address is logged as a warning`() {
val captured = mutableListOf<Pair<Logging.Priority, String>>()
val capturingLogger = object : Logging.Logger {
override fun log(
priority: Logging.Priority,
tag: String,
message: String,
metaData: Map<String, Any>?,
) {
captured.add(priority to message)
}
}
Logging.clearAll()
Logging.install(capturingLogger)
try {
RPAChecker().verify(address = "123", irk = irkHex.fromHex()) shouldBe false
} finally {
Logging.clearAll()
Logging.install(JUnitLogger())
}
captured.any { (priority, message) ->
priority == Logging.Priority.WARN && message.contains("malformed")
} shouldBe true
}
}