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
| 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).
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.
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
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.
We've had to work around this bug in MacPorts.
https://trac.macports.org/ticket/37834#comment:10
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?"