Windows: Catch hresult_error in LE discovery completion chain
BluetoothLEDevice::FromBluetoothAddressAsync and GetGattServicesAsync
completion lambdas call chained WinRT accessors (DeviceInformation(),
Pairing(), Services(), Uuid(), ...). Each accessor runs check_hresult()
on the backing ABI call and throws winrt::hresult_error on failure.
After the Bluetooth stack has torn down state (system suspend/resume,
radio toggled, service restart), those calls routinely fail and the
exception propagates out of the lambda, crashing the process with an
access violation on the failing RaiseException.
Wrap the vulnerable calls in handleLowEnergyDevice with the shared
SAFE()/TRY() helpers from qbluetoothutils_winrt_p.h. SAFE(expr) returns
expr's value on success and a default-constructed value on a caught
hresult_error; TRY(stmt) runs stmt and returns true/false. Both log
the HRESULT.
The covered calls are device.BluetoothAddress() (TRY, so a successfully
read address of 0 -- technically not a valid BD_ADDR per the spec but
allowed by the existing code -- still proceeds, and only an actual
hresult_error causes us to bail), device.Name() (SAFE; an empty hstring
is fine for an unnamed device), device.DeviceInformation().Pairing()
.IsPaired() (SAFE), device.GetGattServicesAsync() (SAFE),
asyncOp.Completed() (TRY; registering the completion handler can also
throw, in which case the handler isn't bound and we have to decrement
the pending counter ourselves), and op.GetResults() inside the
completion lambda (SAFE, so the existing null-check covers both the
thrown and the S_OK-with-null cases with one branch).
In handleGattServices, wrap the whole Status/Services/Uuid block in
try/catch instead of SAFE-wrapping individual calls -- service.Uuid()
returns a winrt::guid that isn't cleanly default-constructible inside
SAFE, and the qScopeGuard at the top already ensures the pending
counter is decremented on any exit path.
Pick-to: 6.11 6.8
Fixes: QTBUG-145898
Change-Id: I9bd6d53773b473ee6d543e1a7e160d91ee08b4a1
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>