Fix panic in create_transaction when payload is not exactly 32 bytes
- Add length check before copy_from_slice to prevent panic - Generate random commitment if payload length is invalid - Fixes issue where empty commitment string caused crash
This commit is contained in:
parent
e205229e92
commit
a8e4cd324a
@ -198,7 +198,12 @@ pub fn create_transaction(
|
|||||||
) -> Result<SilentPaymentUnsignedTransaction> {
|
) -> Result<SilentPaymentUnsignedTransaction> {
|
||||||
let mut commitment = [0u8; 32];
|
let mut commitment = [0u8; 32];
|
||||||
if let Some(ref p) = payload {
|
if let Some(ref p) = payload {
|
||||||
commitment.copy_from_slice(&p);
|
if p.len() == 32 {
|
||||||
|
commitment.copy_from_slice(&p);
|
||||||
|
} else {
|
||||||
|
// If payload is not exactly 32 bytes, generate random commitment
|
||||||
|
thread_rng().fill(&mut commitment);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
thread_rng().fill(&mut commitment);
|
thread_rng().fill(&mut commitment);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user