lightningd: fix format specifier for bitcoin_tx_weight
What changed, and why it matters
This commit fixes the type of placeholder used in debug log messages when printing transaction weight values. On some platforms, using the wrong placeholder can cause the program to crash or print garbage when logging is enabled, but it does not create a security vulnerability that an attacker can exploit. It is a build/robustness fix, not a flaw in transaction handling itself.
No security response required. Treat as a normal code-quality/build fix. If running builds on non-linux/amd64 platforms, ensure this patch is included to avoid potential logging crashes.
Security signals we found
Format specifier mismatch between %lu and size_t arguments
Only affects debug/informational logging paths
No change to arithmetic, fee computation, or protocol logic
Changelog frames fix as a Docker build issue, not a security issue
Evidence from the diff
The patch changes C format specifiers from %lu to %zu for values of type size_t (returned by calc_weight and related helpers). %lu expects unsigned long, while %zu is the correct specifier for size_t. On platforms where size_t and unsigned long differ in width (e.g., some 64-bit or non-amd64 builds), mismatched specifiers can trigger undefined behavior, typically manifesting as incorrect log output or a crash when status_debug/plugin_log is called. The change is purely in logging/debug code and does not alter transaction-weight calculations, fee logic, or consensus behavior.
Changed components
channeld/channeld.c calc_weight and check_balances loggingplugins/spender/splice.c calc_weight and handle_fee_and_ppm loggingInspect captured patch +16 / −16
diff --git a/channeld/channeld.c b/channeld/channeld.c
index b84fd0f9..dfb952bf 100644
--- a/channeld/channeld.c
+++ b/channeld/channeld.c
@@ -3253,7 +3253,7 @@ static size_t calc_weight(enum tx_role role, const struct wally_psbt *psbt,
}
if (log_math)
status_debug(" Adding input"
- " %lu; weight: %lu", i, weight - lweight);
+ " %zu; weight: %zu", i, weight - lweight);
lweight = weight;
}
@@ -3268,7 +3268,7 @@ static size_t calc_weight(enum tx_role role, const struct wally_psbt *psbt,
}
if (log_math)
status_debug(" Adding output"
- " %lu; weight: %lu", i, weight - lweight);
+ " %zu; weight: %zu", i, weight - lweight);
lweight = weight;
}
@@ -3287,12 +3287,12 @@ static size_t calc_weight(enum tx_role role, const struct wally_psbt *psbt,
psbt->num_outputs);
if (log_math)
status_debug(" Adding bitcoin_tx_core_weight;"
- " weight: %lu", weight - lweight);
+ " weight: %zu", weight - lweight);
lweight = weight;
}
if (log_math)
- status_debug("Total weight: %lu", weight);
+ status_debug("Total weight: %zu", weight);
return weight;
}
@@ -3592,7 +3592,7 @@ static struct amount_sat check_balances(struct peer *peer,
if (opener) {
status_debug("User specified fee of %s. Splice feerate %"PRIu32
- " * weight %lu / 1000 = %s",
+ " * weight %zu / 1000 = %s",
fmt_amount_m_as_sat(tmpctx, initiator_fee),
peer->feerate_splice,
calc_weight(TX_INITIATOR, psbt, false),
@@ -3616,7 +3616,7 @@ static struct amount_sat check_balances(struct peer *peer,
true);
status_debug("Our own fee (%s) is too high to use without"
" forcing. Splice feerate %"PRIu32
- " x weight %lu / 1000 = %s (max)",
+ " x weight %zu / 1000 = %s (max)",
fmt_amount_m_as_sat(tmpctx, initiator_fee),
peer->feerate_splice,
calc_weight(TX_INITIATOR, psbt, false),
@@ -3627,7 +3627,7 @@ static struct amount_sat check_balances(struct peer *peer,
splice_abort(peer, NULL,
"Our own fee (%s) is too high to use without"
" forcing. Splice feerate %"PRIu32
- " x weight %lu / 1000 = %s (max)",
+ " x weight %zu / 1000 = %s (max)",
fmt_amount_m_as_sat(tmpctx, initiator_fee),
peer->feerate_splice,
calc_weight(TX_INITIATOR, psbt, false),
diff --git a/plugins/spender/splice.c b/plugins/spender/splice.c
index a0ca725d..7d0bab26 100644
--- a/plugins/spender/splice.c
+++ b/plugins/spender/splice.c
@@ -869,7 +869,7 @@ static size_t calc_weight(struct splice_cmd *splice_cmd,
*/
for (size_t i = 0; i < psbt->num_inputs; i++) {
weight += psbt_input_get_weight(psbt, i, PSBT_GUESS_2OF2);
- plugin_log(plugin, LOG_DBG, " Counting input; weight: %lu",
+ plugin_log(plugin, LOG_DBG, " Counting input; weight: %zu",
weight - lweight);
lweight = weight;
}
@@ -879,7 +879,7 @@ static size_t calc_weight(struct splice_cmd *splice_cmd,
weight += bitcoin_tx_input_weight(false,
bitcoin_tx_input_witness_weight(UTXO_P2TR) - 1);
plugin_log(plugin, LOG_DBG, " Simulating input (wallet);"
- " weight: %lu", weight - lweight);
+ " weight: %zu", weight - lweight);
lweight = weight;
}
@@ -891,7 +891,7 @@ static size_t calc_weight(struct splice_cmd *splice_cmd,
bitcoin_tx_2of2_input_witness_weight() - 1);
plugin_log(plugin, LOG_DBG, " Simulating input"
" (channel); weight:"
- " %lu", weight - lweight);
+ " %zu", weight - lweight);
lweight = weight;
extra_inputs++;
}
@@ -909,7 +909,7 @@ static size_t calc_weight(struct splice_cmd *splice_cmd,
weight += bitcoin_tx_output_weight(BITCOIN_SCRIPTPUBKEY_P2WSH_LEN);
plugin_log(plugin, LOG_DBG, " Simulating output"
" (channel); weight:"
- " %lu", weight - lweight);
+ " %zu", weight - lweight);
lweight = weight;
extra_outputs++;
@@ -921,13 +921,13 @@ static size_t calc_weight(struct splice_cmd *splice_cmd,
extra_outputs++;
plugin_log(plugin, LOG_DBG, " Simulating output"
" (wallet); weight:"
- " %lu", weight - lweight);
+ " %zu", weight - lweight);
lweight = weight;
}
for (size_t i = 0; i < psbt->num_outputs; i++) {
weight += psbt_output_get_weight(psbt, i);
- plugin_log(plugin, LOG_DBG, " Adding output; weight: %lu",
+ plugin_log(plugin, LOG_DBG, " Adding output; weight: %zu",
weight - lweight);
lweight = weight;
}
@@ -945,10 +945,10 @@ static size_t calc_weight(struct splice_cmd *splice_cmd,
weight += bitcoin_tx_core_weight(psbt->num_inputs + extra_inputs,
psbt->num_outputs + extra_outputs);
plugin_log(plugin, LOG_DBG, " Adding bitcoin_tx_core_weight;"
- " weight: %lu", weight - lweight);
+ " weight: %zu", weight - lweight);
lweight = weight;
- plugin_log(plugin, LOG_DBG, "Total weight: %lu", weight);
+ plugin_log(plugin, LOG_DBG, "Total weight: %zu", weight);
return weight;
}
@@ -1389,7 +1389,7 @@ static struct command_result *handle_fee_and_ppm(struct command *cmd,
plugin_log(cmd->plugin, LOG_INFORM,
"Splice fee is %s at %"PRIu32" perkw (%.02f sat/vB) "
- "on tx where our weight units are %lu",
+ "on tx where our weight units are %zu",
fmt_amount_sat(tmpctx, onchain_fee),
splice_cmd->feerate_per_kw,
4 * splice_cmd->feerate_per_kw / 1000.0f,
Why this scored 19/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.