mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 14:11:39 +00:00
kernel: document that btck_WriteBytes may receive a null pointer #36418
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36418
Loading…
Reference in a new issue
No description provided.
Delete branch "kernel-writebytes-nonnull"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The header does not say whether the bytes pointer can be null when size is zero. It can:
btck_witness_stack_get_item_atpassesstd::vector::data()straight through, and that may be null for an empty element.An alternative is to guarantee non-null rather than document that it isn't. In other words, route the vector-backed writer calls through a helper that substitutes a valid, never-read pointer when the buffer is empty.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Base:
9dfde64cc3262329051fd05fffe40eecc786a99fHead:
b497a71c6630fe37f25620f9f08f1c52f9d4d558Findings
Minor
The in-tree callback is unsafe for the documented null case (src/kernel/bitcoinkernel.h:394, head)
When
bytesis null andsizeis zero, the in-tree C++ callback insrc/kernel/bitcoinkernel_wrapper.hcomputesfirst + lenbefore inserting the range. Even adding zero to a null pointer is undefined behavior.ScriptPubkey::ToBytes()reaches this callback throughbtck_script_pubkey_to_bytes, and empty scripts are supported. The existingempty_scripttest exercises this path but does not detect the undefined pointer arithmetic. Return from the callback whenlen == 0, or otherwise handle the null case without pointer arithmetic. No non-test caller of this convenience method was identified, so production impact is unconfirmed.Review coverage was incomplete. adversarial_glm: Output failed validation: Finding must identify a positive line
Full review report
ACK
76359bee61Documenting this seems like the correct call, given that developers can, and should probably, already check if the size is zero.
Approach ACK, documenting seems like the best choice now.
The commit message in
76359besays that this is relevant only to bindings, but I think it also matters to C users, for example when they givebytestomemcpy. I suggest this more general alternative:Documenting how callers should deal with this seems out of scope, would just describe behaviour. Let's also use more complete Doxygen syntax while we're at it.
git diff on
76359bee61Taken - thanks!
Taken - thanks!
ACK
b497a71c66ACK
b497a71c66