Invalidate iterator->first on dtor to expose use-after-free#1409
Merged
jbeder merged 1 commit intojbeder:masterfrom Feb 28, 2026
Merged
Invalidate iterator->first on dtor to expose use-after-free#1409jbeder merged 1 commit intojbeder:masterfrom
jbeder merged 1 commit intojbeder:masterfrom
Conversation
Contributor
|
very cool! if I understand correctly, it doesn't really fix the bug, but makes it much more likely to be detected at run time, right? |
Contributor
Author
|
Yes, this PR will make developers notice the wrong usage if only it's executed.
…---Original---
From: "Simon Gene ***@***.***>
Date: Fri, Feb 27, 2026 23:02 PM
To: ***@***.***>;
Cc: "Dahan ***@***.******@***.***>;
Subject: Re: [jbeder/yaml-cpp] Invalidate iterator->first on dtor to exposeuse-after-free (PR #1409)
SGSSGene left a comment (jbeder/yaml-cpp#1409)
very cool! if I understand correctly, it doesn't really fix the bug, but makes it much more likely to be detected at run time, right?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
Nodevariable's iterator creates temporary variables (iterator_base::proxy) to expose an array element or mapped key+value of the node. However this usage may cause dangling pointers onproxy.firstandproxy.second.Here is a demo:
The
invalid_noderefers to a destroyedproxy-typed variable, and then:invalid_node.Scalar(), then it may returnstd::string("key")as expected.This PR will fix this undefined behavior, by always filling memory region of
proxyvariables with0, and then such a wrong usage will always cause a crash.Also fix #1071 .