mktemp: Fix template validation to require trailing consecutive Xs#10224
Merged
Conversation
Contributor
|
Please add tests to make sure we don't regress in the future |
…s that do not end with a sufficient X run
sylvestre
reviewed
Jan 13, 2026
sylvestre
reviewed
Jan 13, 2026
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Change logic to only accept templates where the run of Xs containing the final 'X' is at least 3 characters long. This fixes cases like "XXX_XX", which should error with "too few X's in template", and allows "tempXXXlate", matching GNU mktemp
|
GNU testsuite comparison: |
cakebaker
reviewed
Jan 15, 2026
CodSpeed Performance ReportMerging this PR will degrade performance by 27.39%Comparing Summary
Performance Changes
Footnotes
|
Contributor
|
Thanks for your PR! |
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.
Closes #10187
The validation logic now checks only the trailing placeholder block, as GNU mktemp requires. It walks backward from the end of the template and counts consecutive X bytes. The template is accepted only if the trailing run has length ≥ 3.
Problem
The previous implementation accepted templates containing
"XXX"anywhere, which incorrectly allowed cases where the template does not end with a sufficient run ofXs (e.g.XXX_foo) or where an earlier"XXX"masked an invalid suffix.Implementation details
s.len()and walks left while bytes areb'X'.Xrun.Xbytes and compute indices from the end boundary.Result
Xs