Skip to content

Avoid accessing legacy TLV fields after the TLV-stream read #3622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

TheBlueMatt
Copy link
Collaborator

legacy fields in TLV stream reads may be used to read fields which are later moved into some other field using either default_value or static_value "reads". This works fine if the field supports copy semantics, however if it does not, the accessing of the field in _decode_and_build after the TLV stream read completes but before the struct is built results in a "use after move" error.

Instead, here, we drop the attempt to hide unused variable warnings entirely, dropping the post-TLV-stream access to legacy variables, allowing their use in move semantics for later fields.

For a demonstration of using this, see the last commit at https://git.bitcoin.ninja/?p=rust-lightning;a=log;h=refs/heads/2025-02-3611-ser-impl

`legacy` fields in TLV stream reads may be used to read fields
which are later moved into some other field using either
`default_value` or `static_value` "reads". This works fine if the
field supports copy semantics, however if it does not, the
accessing of the field in `_decode_and_build` after the TLV stream
read completes but before the struct is built results in a "use
after move" error.

Instead, here, we drop the attempt to hide unused variable warnings
entirely, dropping the post-TLV-stream access to legacy variables,
allowing their use in move semantics for later fields.
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.59%. Comparing base (1610854) to head (0452241).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3622      +/-   ##
==========================================
- Coverage   88.60%   88.59%   -0.01%     
==========================================
  Files         151      151              
  Lines      118454   118454              
  Branches   118454   118454              
==========================================
- Hits       104957   104949       -8     
+ Misses      10985    10983       -2     
- Partials     2512     2522      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace valentinewallace merged commit 047bd61 into lightningdevkit:main Feb 26, 2025
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants