script: Fix undefined behavior in Clone() -- std::transform writes past end of empty vector#34700
Conversation
…st end of empty vector
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste |
|
Can you provide a unit test that triggers the UB before the patch is applied? That will help with review. |
@pinheadmz Done |
|
Was this LLM generated? What are the steps to test this? What is the output before and after the changes here? |
|
build test_bitcoin with this patch output ok like: without this patch output like: |
|
Mostly, I am writing golang. https://github.com/golang/go/commits?author=cuiweixie most pr is before LLM got popular. |
|
Ok, I see. This is actually dead/unreachable code, so the fix isn't urgent. About the test: I think it is a bit too spicy to include the c++ file in such a way to test this. I'd say it is fine to drop the commit, but no strong opinion. |
Drop the unittest case commit. |
|
lgtm ACK 44feab2 Seems fine to fix UB in dead and unreachable code as a small style cleanup. However, for the pull description, I'd recommend to remove the sections
|
Done |
|
Do we need other change before merge this pr? if not, maybe just merge this pr. |
frankomosh
left a comment
There was a problem hiding this comment.
Code Review ACK 44feab2. Fix seems minimal and correct.
Motivation
This patch fixes undefined behavior in Clone() in src/script/descriptor.cpp.
When std::transform is used with providers.begin() or subdescs.begin() as the output iterator, the vectors have been reserve()d but have size 0. Writing through begin() in that case writes past the logical end of the vector, which is undefined behavior.