From ce6efdd78288dc6b0c1d234e929794eca7f251bd Mon Sep 17 00:00:00 2001 From: toller892 Date: Tue, 2 Jun 2026 19:57:46 +0800 Subject: [PATCH] fix: prevent panic on no-op contract extend for non-existent entries When is called against a non-existent contract ID, the transaction succeeds as a no-op (empty changes). The code then tries to fetch the ledger entry and access without checking if the entries list is empty, causing an index-out-of-bounds panic. Also add a guard for the changes array having fewer than 2 elements before matching on and , preventing a potential panic on malformed transaction meta. Fixes #2599 --- cmd/soroban-cli/src/commands/contract/extend.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/soroban-cli/src/commands/contract/extend.rs b/cmd/soroban-cli/src/commands/contract/extend.rs index 3d0cff87c..dcf94f554 100644 --- a/cmd/soroban-cli/src/commands/contract/extend.rs +++ b/cmd/soroban-cli/src/commands/contract/extend.rs @@ -285,11 +285,17 @@ impl Cmd { if changes.is_empty() { print.infoln("No changes detected, transaction was a no-op."); let entry = client.get_full_ledger_entries(&keys).await?; + if entry.entries.is_empty() { + return Err(Error::LedgerEntryNotFound); + } let extension = entry.entries[0].live_until_ledger_seq.unwrap_or_default(); return Ok(TxnResult::Res(extension)); } + if changes.len() < 2 { + return Err(Error::LedgerEntryNotFound); + } match (&changes[0], &changes[1]) { ( LedgerEntryChange::State(_),