Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mktemp: wrong prefix verification #4378

Closed
ZauJulio opened this issue Feb 16, 2023 · 4 comments · Fixed by #4379
Closed

mktemp: wrong prefix verification #4378

ZauJulio opened this issue Feb 16, 2023 · 4 comments · Fixed by #4379

Comments

@ZauJulio
Copy link
Contributor

Discovery

I started testing uutils/coreutils using the AUR package from coreutils-hybrid, it merges the uutils packages with the ones missing from the standard GNU . I use dracut to resolve the initframes, however when I updated the kernel and the initframes would be recreated I got the following error:

dracut: mktemp -p '/var/tmp/' -d -t dracut.XXXXXX failed.

I checked and found that the mktemp package came from coreutils and that it was already available in uutils.

Issue

Let me tell you that I don't program in Rust, not so much in C. Checking the code of both versions I realized that maybe the author of the code checked the prefix after the join with the path.

Solution

What I did was change the check to prefix only. Passed the tests and apparently everything is ok.

+ // Check that the prefix is valid.
+ let prefix_of_template = Path::new(prefix_from_template).display().to_string();

+ if options.treat_as_template && prefix_of_template.contains(MAIN_SEPARATOR) {
    return Err(MkTempError::PrefixContainsDirSeparator(options.template));
}

[NOTICE]: I'm from Brazil, it's Carnaval, so maybe I won't respond so quickly 🥳 🍺 🏖️

@ZauJulio
Copy link
Contributor Author

Here is the call that caused the issue with Dracut, after patching my machine everything is ok:

https:/dracutdevs/dracut/blob/master/dracut.sh#L1245

@ZauJulio

This comment was marked as duplicate.

@sylvestre
Copy link
Contributor

please replace your screenshot by text.
Screenshots are terrible for:

  • search
  • accessibility
    thanks

@jfinkels
Copy link
Collaborator

jfinkels commented Feb 18, 2023

I was able to reproduce the issue from the screenshot:

GNU mktemp:

$ mktemp -p . -d -t dracut.XXXXXX
./dracut.LiEl2D

uutils mktemp:

$ ./target/debug/mktemp -p . -d -t dracut.XXXXXX
./target/debug/mktemp: invalid template, 'dracut.XXXXXX', contains directory separator

Good bug find. The mktemp behavior has been tricky to get right.

Edit: by the way, the GNU mktemp version I used is 8.30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants