Repository navigation
sudo_preload_dso_alloc: advance the write pointer, not the array base - #609
Merged
Merged
Conversation
millert
approved these changes
Nov 30, 2026
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.
sudo_preload_dso_alloc()builds the command's new environment innenvpand appends to it through the cursornep, but the branch that addsRTLD_PRELOAD_ENABLE_VARwrites throughnenvp. That overwrites the first copied environment variable and leaves the returned pointer one element past the allocation base, so the command loses that variable, the enable variable never reaches it (the slot it landed in is the one that gets skipped), and the caller frees a pointer that is not the one that was allocated.RTLD_PRELOAD_ENABLE_VARis only set by configure for Darwin 7 and earlier and for NeXTSTEP, so the branch is not compiled on current platforms, but where it is,disable_execute()cannot turn the preload on at all and aNOEXECrule has no effect on the command.Append through
neplike the other two appends in the function.env_sizealready reserves a slot for this entry whendso_enabledis false, so the buffer is still large enough. This is the only place in the tree that advances the array rather than the cursor.Repro: build
src/exec_preload.cwith-DRTLD_PRELOAD_ENABLE_VAR='"DYLD_FORCE_FLAT_NAMESPACE"'and callsudo_preload_dso()with{"FIRST=1", "SECOND=2", "THIRD=3"}. Before, the result starts atSECOND=2, contains noDYLD_FORCE_FLAT_NAMESPACE, and AddressSanitizer reportsattempting free on address which was not malloc()-ed ... 8 bytes inside of 48-byte regionwhen the array is freed, which is whatsrc/sudo_intercept.cdoes with it. After, all three variables and the enable variable are there and the free is clean. I also checked the existing preload variable, duplicateSUDO_INTERCEPT_FD, emptyenvpand already-enabled cases.make checkpasses.