misc: fix uninitialised errors for macOS
What changed, and why it matters
This commit fixes compiler warnings that macOS treats as errors. Most changes simply initialize variables to zero or remove an unused variable. One change in the dual-funding code replaces a previously declared but uninitialized channel identifier with an existing one from the state object, which could prevent use of stale or random memory.
Treat as a low-risk hardening patch. Review whether state->channel_id is fully populated before the opener_commits call to confirm the replacement is safe. No urgent action required.
Security signals we found
Use of potentially uninitialized stack variable in dual-funding path (cid replaced by state->channel_id)
Uninitialized secp256k1_ecdsa_signature in lease validation path zero-initialized
No explicit security framing by the vendor; treated as compiler warning cleanup
Evidence from the diff
The patch addresses uninitialized-variable diagnostics. In run-trace.c and mkquery.c variables are zero-initialized or set to NULL. In lightningd/dual_open_control.c a stack-allocated secp256k1 signature is zero-initialized. In openingd/dualopend.c the local struct channel_id cid is removed and replaced with state->channel_id. The commit message frames this as a macOS build fix, not a security fix.
Changed components
openingd/dualopend.clightningd/dual_open_control.cdevtools/mkquery.ccommon/test/run-trace.cInspect captured patch +6 / −7
diff --git a/common/test/run-trace.c b/common/test/run-trace.c
index 7811f68c..e257d445 100644
--- a/common/test/run-trace.c
+++ b/common/test/run-trace.c
@@ -8,7 +8,7 @@
int main(int argx, char *argv[])
{
/* Just some context objects to hang spans off of. */
- int a, b, c, d;
+ int a = 0, b = 0, c = 0, d = 0;
common_setup(argv[0]);
diff --git a/devtools/mkquery.c b/devtools/mkquery.c
index 9fe6e69f..d7507512 100644
--- a/devtools/mkquery.c
+++ b/devtools/mkquery.c
@@ -17,7 +17,7 @@ int main(int argc, char *argv[])
{
struct bitcoin_blkid chainhash;
const tal_t *ctx = tal(NULL, char);
- const u8 *msg;
+ const u8 *msg = NULL;
setup_locale();
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY |
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
strtol(argv[3], NULL, 0),
strtol(argv[4], NULL, 0));
} else if (streq(argv[1], "query_channel_range")) {
- struct tlv_query_channel_range_tlvs *tlvs;
+ struct tlv_query_channel_range_tlvs *tlvs = NULL;
if (argc == 5)
tlvs = NULL;
else if (argc == 6) {
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
strtol(argv[4], NULL, 0),
tlvs);
} else if (streq(argv[1], "query_short_channel_ids")) {
- struct tlv_query_short_channel_ids_tlvs *tlvs;
+ struct tlv_query_short_channel_ids_tlvs *tlvs = NULL;
u8 *encoded;
if (argc == 4)
diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c
index ed75f5d7..a605a528 100644
--- a/lightningd/dual_open_control.c
+++ b/lightningd/dual_open_control.c
@@ -2251,7 +2251,7 @@ static bool verify_option_will_fund_signature(struct peer *peer,
static void handle_validate_lease(struct subd *dualopend,
const u8 *msg)
{
- const secp256k1_ecdsa_signature sig;
+ secp256k1_ecdsa_signature sig = {{0}};
u16 chan_fee_max_ppt;
u32 chan_fee_max_base_msat, lease_expiry;
struct pubkey their_pubkey;
diff --git a/openingd/dualopend.c b/openingd/dualopend.c
index f03f1b92..2b3ff44b 100644
--- a/openingd/dualopend.c
+++ b/openingd/dualopend.c
@@ -2794,7 +2794,6 @@ static u8 *opener_commits(struct state *state,
struct amount_sat total,
char **err_reason)
{
- struct channel_id cid;
struct amount_msat our_msats;
struct penalty_base *pbase;
struct bitcoin_tx *local_commit;
@@ -2853,7 +2852,7 @@ static u8 *opener_commits(struct state *state,
tal_free(state->channel);
state->channel = new_initial_channel(state,
- &cid,
+ &state->channel_id,
&tx_state->funding,
state->minimum_depth,
take(new_height_states(NULL, LOCAL,
Why this scored 24/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.