tools/generate-wire.py: don't set TLV fields to NULL if they're empty.
What changed, and why it matters
This is a one-line code generator fix in Core Lightning's wire protocol tooling. Previously, when a variable-length array field (common in newer Lightning protocol messages like BOLT 12) had zero elements, the generated code set the pointer to NULL. Now it always allocates an empty array. This corrects behavior where an empty-but-present list could be mistaken for a missing list, which could cause protocol compliance failures or logic errors in BOLT 12 features.
Review generated parsers and any code paths that test variable-length array pointers against NULL to ensure they now correctly handle empty arrays. Consider whether any existing checks rely on NULL to mean 'field absent' and update them. No immediate emergency patch is indicated, but the change should be included in the next release.
Security signals we found
Protocol parser semantic change: empty array now distinguished from missing field
BOLT 12 / TLV parsing context
Potential for logic bugs where NULL was interpreted as absent
No explicit security claim in commit message
Evidence from the diff
tools/gen/impl_template is a Mako template used by tools/generate-wire.py to produce C fromwire functions for protocol messages. The change removes a conditional that set empty variable-length array fields to NULL, instead always calling tal_arr(ctx, type, 0). This affects how generated parsers represent zero-length TLV arrays. The commit message ties this to a new BOLT 12 test that expects an empty ->currencies array to be considered present rather than missing. The patch is narrow and only touches the empty-array case for variable-length fields.
Changed components
tools/gen/impl_templatetools/generate-wire.pyGenerated fromwire_* C parsers for variable-length array fieldsBOLT 12 TLV message parsingInspect captured patch +1 / −1
diff --git a/tools/gen/impl_template b/tools/gen/impl_template
index c3b97d5f..7308aac6 100644
--- a/tools/gen/impl_template
+++ b/tools/gen/impl_template
@@ -91,7 +91,7 @@ ${fieldname} = tal_arr(${ctx}, ${typename}, ${f.size('*plen')});
fromwire_${type_}_array(cursor, plen, ${fieldname}, ${f.size('*plen')});
% else:
% if f.is_varlen():
-${fieldname} = ${f.size('*plen')} ? tal_arr(${ctx}, ${typename}, 0) : NULL;
+${fieldname} = tal_arr(${ctx}, ${typename}, 0);
% endif
% if f.is_implicit_len():
while (*plen != 0) {
Why this scored 35/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.