llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang is unable to make temporary file when a directory owned by another user with the same basename as the file being compiled exists in /tmp

Open jordypotman opened this issue 14 years ago • 5 comments

Bugzilla Link 13511
Resolution FIXED
Resolved on Sep 09, 2013 07:16
Version trunk
OS Linux
CC @ryandesign,@simonpcook

Extended Description

Steps to reproduce: $ cat test.c int main(void) { } $ sudo mkdir /tmp/test $ clang test.c clang: error: unable to make temporary file: /tmp/test: can't make unique filename: Permission denied $ clang -v clang version 3.2 (http://llvm.org/git/clang.git 207c408b14f0c29d65d6ad311456be94b812d5dd) (http://llvm.org/git/llvm.git 1c3781496081b47412fc70393bcdc5b67b440b02) Target: x86_64-unknown-linux-gnu Thread model: posix

It works fine if /tmp contains a file test owned by root instead of a directory test: $ sudo rmdir /tmp/test $ sudo touch /tmp/test $ clang test.c

This is caused by Path::makeUnique trying to make a unique directory in path if path is a directory instead of making path unique (line 829 and further in llvm/lib/Support/Unix/Path.inc).

jordypotman avatar Aug 02 '12 14:08 jordypotman

This issue cannot be reproduced anymore with LLVM/clang built from the latest SVN trunk.

I guess this was fixed by Rafael's changes to remove PathV1.

jordypotman avatar Sep 09 '13 14:09 jordypotman

I too have run into this problem. I'm on Mac OS X (10.8.4) using the system clang (Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)). I had created the directory /tmp/opt as one user (to install some software temporarily), and I was building ffmpeg as a different user. The ffmpeg build failed when it tried to compile libavutil/opt.o:

clang: error: unable to make temporary file: /tmp/opt: can't make unique filename: Permission denied

llvmbot avatar Sep 06 '13 21:09 llvmbot

Poke, prod.

I hit this on FreeBSD as well recently with a buildworld and it's an awesome potential for race conditions with multiple builds being run in parallel, or potential for a security exploit.

llvmbot avatar May 09 '13 00:05 llvmbot

We've had to work around this bug in MacPorts.

https://trac.macports.org/ticket/37834#comment:10

ryandesign avatar Feb 28 '13 13:02 ryandesign

Is it strictly necessary to create the temporary file in the directory if it exist or done for any particular reason instead of appending to the file name as is the case otherwise?

I think solutions to this are either: a) Remove the directory test and always append -XXXXXX instead of trying in the directory /XXXXXX (I personally do not see any issues with this option, unless there is a particular reason for trying to insert into the directory first) b) Expand the test for which pattern to use to be "is this a directory and can I write in it?"

simonpcook avatar Aug 08 '12 13:08 simonpcook