Re: fix mktemp (remove mktemp ;)

2005-04-18 Thread Florian Weimer
* Herbert Xu: > Paul Jackson <[EMAIL PROTECTED]> wrote: >> >> Even mktemp(1) can collide, in theory, since there is no practical way >> in shell scripts to hold open and locked the file from the instant of it >> is determined to be a unique name. > > mktemp(1) creates the file before exiting. Ot

Re: fix mktemp (remove mktemp ;)

2005-04-17 Thread Paul Jackson
Herbert wrote: > mktemp(1) creates the file before exiting. ... O_EXCL Aha - right you are. Thanks for pointing that out. -- I won't rest till it's the best ... Programmer, Linux Scalability Paul Jackson <[EMAIL PROTECTED]> 1.650.933.1373,

Re: fix mktemp (remove mktemp ;)

2005-04-17 Thread Herbert Xu
Paul Jackson <[EMAIL PROTECTED]> wrote: > > Even mktemp(1) can collide, in theory, since there is no practical way > in shell scripts to hold open and locked the file from the instant of it > is determined to be a unique name. mktemp(1) creates the file before exiting. Other instances of mktemp(

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
> No, you have to: How does this compare with the one I posted about 1 hour 30 minuts ago: tmp=${TMPDIR-/tmp} tmp=$tmp/gitdiff-do.$RANDOM.$RANDOM.$RANDOM.$$ (umask 077 && mkdir $tmp) || { echo "Could not create temporary directory! Exiting." 1>&2

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Brian O'Mahoney
No, you have to: (a) create a unique, pid specific file name /var/tmp/myapp.$$.xyzzy (b) create it in O_EXCL mode, so you wont smash another's held lock (b-1) It worked, OK (b-2) open failed, try ...xyzzz repeat until (b-1) There are thousands of examples of how to do this with bash. Paul Jack

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
Erik wrote: > How about putting using .git/tmp.$$ or similar as tempfile? One could, but best to normally honor the users TMPDIR setting. Could one 'git diff' a readonly git repository? Perhaps someone has a reason for putting their tmp files where they choose - say a local file system in a heav

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
Dave wrote: > http://www.linuxsecurity.com/content/view/115462/151/ Nice - thanks. Pasky - would you be interested in a patch that used a more robust tmp file creation, along the lines of replacing t=${TMPDIR:-/usr/tmp}/gitdiff.$$ trap 'set +f; rm -fr $t.?; trap 0; exit 0' 0 1 2

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread David Lang
ks in this directory) David Lang On Sat, 16 Apr 2005, Dave Jones wrote: Date: Sat, 16 Apr 2005 20:57:57 -0400 From: Dave Jones <[EMAIL PROTECTED]> To: Paul Jackson <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED], git@vger.kernel.org, [EMAIL PROTECTED] Subject: Re: fix mktemp (remove mktemp

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Dave Jones
On Sat, Apr 16, 2005 at 05:44:09PM -0700, Paul Jackson wrote: > Dave wrote: > > mktemp is being used here to provide randomness in the filename, > > not just a uniqueness. > > Ok - useful point. > > How about: > > t=${TMPDIR:-/usr/tmp}/gitdiff.$$.$RANDOM pid is still predictable b

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Erik van Konijnenburg
On Sat, Apr 16, 2005 at 08:33:25PM -0400, Dave Jones wrote: > On Sat, Apr 16, 2005 at 05:02:21PM -0700, Paul Jackson wrote: > > > And racy. And not guaranteed to come up with fresh new files. > > > > In theory perhaps. In practice no. > > > > Even mktemp(1) can collide, in theory, since the

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
Dave wrote: > mktemp is being used here to provide randomness in the filename, > not just a uniqueness. Ok - useful point. How about: t=${TMPDIR:-/usr/tmp}/gitdiff.$$.$RANDOM > all an attacker has to do is create 65535 symlinks in /usr/tmp And how about if I removed the tmp files at th

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Dave Jones
On Sat, Apr 16, 2005 at 05:02:21PM -0700, Paul Jackson wrote: > > And racy. And not guaranteed to come up with fresh new files. > > In theory perhaps. In practice no. > > Even mktemp(1) can collide, in theory, since there is no practical way > in shell scripts to hold open and locked the f

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
> And racy. And not guaranteed to come up with fresh new files. In theory perhaps. In practice no. Even mktemp(1) can collide, in theory, since there is no practical way in shell scripts to hold open and locked the file from the instant of it is determined to be a unique name. The window of vul

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Petr Baudis
Dear diary, on Sun, Apr 17, 2005 at 01:27:43AM CEST, I got a letter where Paul Jackson <[EMAIL PROTECTED]> told me that... > Remove mktemp usage - it doesn't work on > some Mandrakes, nor on my SuSE 8.2 with > mktemp-1.5-531. > > Replace with simple use of $$ (pid). > I've been using this same pat