vendorCargoRegistries: avoid escaping shell args#1045
Open
llakala wants to merge 1 commit into
Open
Conversation
ipetkov
reviewed
Jun 26, 2026
| mkdir -p $out | ||
| ${concatMapStrings (p: '' | ||
| ln -s ${escapeShellArg (vendorCrate p)} $out/${escapeShellArg "${p.name}-${p.version}"} | ||
| ln -s ${vendorCrate p} $out/${p.name}-${p.version} |
Owner
There was a problem hiding this comment.
vendorCrate pshould be a store path yes, but can store paths contain spaces? If not the/nix/store/<hash>-<name>path, what about subdirectories? Technically the caller can override the download derivation with whatever they want. Maybe its their own fault if they do a shell injection, but escaping here is a foolproof way of dealing with quoting- I'd strongly prefer we keep escaping
${p.name}-${p.version}. There's probably a number of different ways to set them to something potentially evil
Author
There was a problem hiding this comment.
- How about we just always quote?
ln -s '${vendorCrate }'. Depends on whether subdirectories can contain'. - I can live with that. Although it would need single quotes for escapeShellArg to do anything, which your example doesn't use.
Owner
There was a problem hiding this comment.
If overrideVendorCargoPackage returns a quoted path quoting it again might end up "undoing" the quotes
| in | ||
| '' | ||
| [source.${escapeShellArg name}] | ||
| [source.${name}] |
Owner
There was a problem hiding this comment.
The original motivation for escaping name here was to avoid potential quoting issues, though its probably the wrong tool for the job anyway. I suppose these are directly controlled by the caller (via whatever registries they have configured directly in the craneLib instantiation) so I'm okay with relaxing this
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.
Motivation
Using the evaluation profiler showed me that this was a surprisingly hot call. I believe all of these uses are unnecessary.
The result of
vendorCrate pshould just be a store path, and the result ofescapeShellArg nameis known info, since there's only one name (crates.io).escapeShellArg "${p.name}-${p.version}"could technically be an issue, so if it's preferred, I can drop this one - but it would require a horrible name and version to trigger.Checklist
docs/API.md(or general documentation) with changesCHANGELOG.md