Skip to content

Commit

Permalink
[Electric-Coin-Company#1420] Synchronizer.proposeShielding crashes wh…
Browse files Browse the repository at this point in the history
…en there are insufficient funds to shield

- Check for the null value of the pointer when constructing propose shielding

[Electric-Coin-Company#1420] Synchronizer.proposeShielding crashes when there are insufficient funds to shield

- throw an error instead of returning nil value

[Electric-Coin-Company#1420] Synchronizer.proposeShielding crashes when there are insufficient funds to shield

- Changelog updated
- Error message polished a bit
  • Loading branch information
LukasKorba committed May 14, 2024
1 parent 31a5848 commit 233a963
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

## Fixed
- The backend method proposeShielding checks the pointer for a null value before attempting to construct the Data with it. Without this check, proposeShielding would crash when there were either zero funds to shield or when the amount was less than the threshold defined by the client.

# 2.1.5 - 2024-04-18

## Changed
Expand Down
8 changes: 6 additions & 2 deletions Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,15 @@ struct ZcashRustBackend: ZcashRustBackendWelding {
)

guard let proposal else {
throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "`proposeShielding` failed with unknown error"))
throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "Failed with nil proposal."))
}

defer { zcashlc_free_boxed_slice(proposal) }


guard proposal.pointee.ptr != nil else {
throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "Insufficient funds to shield."))
}

return try FfiProposal(contiguousBytes: Data(
bytes: proposal.pointee.ptr,
count: Int(proposal.pointee.len)
Expand Down

0 comments on commit 233a963

Please sign in to comment.