git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: fix mktemp (remove mktemp ;)

From
BOBrian O'Mahoney <omb@khandalf.com>
Date
Apr 17, 2005, 02:38 UTC
Message-ID
<4261CC35.4070108@khandalf.com>
In-Reply-To
<20050416174409.59f94c26.pj@sgi.com>

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 Jackson wrote:
Show 14 quoted lines
> 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

the point of the xyzzy seed is to make creating all possible files in-feasable.

Show 27 quoted lines
> 
> 
> And how about if I removed the tmp files at the top:
> 
> 	t=${TMPDIR:-/usr/tmp}/gitdiff.$$.$RANDOM
> 	trap 'rm -fr $t.?; trap 0; exit 0' 0 1 2 3 15
> 	rm -fr $t.?
> 
> 	... rest of script ...
> 
> How close does that come to providing the same level of safety, while
> remaining portable over a wider range of systems, and not requiring that
> a separate command be forked?
> 
> 
>>I'd suggest fixing your distributions ...
> 
> 
> It's not just my distro; it's the distros of all git users.
> 
> If apps can avoid depending on inessential details of their
> environment, that's friendlier to all concerned.
> 
> And actually my distro is fine - it's just that I am running an old
> version of it on one of my systems.  Newer versions of the mktemp -t
> option.
> 
-- 
mit freundlichen Grüßen, Brian.

Dr. Brian O'Mahoney
Mobile +41 (0)79 334 8035 Email: omb@bluewin.ch
Bleicherstrasse 25, CH-8953 Dietikon, Switzerland
PGP Key fingerprint = 33 41 A2 DE 35 7C CE 5D  F5 14 39 C9 6D 38 56 D5
Previous: Paul JacksonNext: Paul Jackson
Message 19 of 25 in “fix mktemp (remove mktemp ;)”
  1. fix mktemp (remove mktemp ;)Paul Jackson, Apr 16, 2005
  2. missing mkdir -p flag in gitdiff-doPaul Jackson, Apr 16, 2005
  3. optimize gitdiff-do scriptPaul Jackson, Apr 16, 2005
  4. Petr BaudisApr 16, 2005
  5. Paul JacksonApr 17, 2005
  6. Paul JacksonApr 18, 2005
  7. Petr BaudisApr 18, 2005
  8. Paul JacksonApr 18, 2005
  9. Paul JacksonMay 10, 2005
  10. Jan-Benedict GlawApr 16, 2005
  11. Paul JacksonApr 16, 2005
  12. Petr BaudisApr 16, 2005
  13. Paul JacksonApr 17, 2005
  14. Dave JonesApr 17, 2005
  15. Paul JacksonApr 17, 2005
  16. Dave JonesApr 17, 2005
  17. David LangApr 17, 2005
  18. Paul JacksonApr 17, 2005
  19. Brian O'MahoneyApr 17, 2005
  20. Paul JacksonApr 17, 2005
  21. Erik van KonijnenburgApr 17, 2005
  22. Paul JacksonApr 17, 2005
  23. Herbert XuApr 18, 2005
  24. Paul JacksonApr 18, 2005
  25. Florian WeimerApr 18, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.