coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

mktemp: wrong prefix verification

Open ZauJulio opened this issue 3 years ago • 4 comments

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 avatar Feb 16 '23 21:02 ZauJulio

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

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

ZauJulio avatar Feb 16 '23 21:02 ZauJulio

image

ZauJulio avatar Feb 16 '23 21:02 ZauJulio

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

  • search
  • accessibility thanks

sylvestre avatar Feb 16 '23 21:02 sylvestre

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.

jfinkels avatar Feb 18 '23 16:02 jfinkels