File: 05_mktemp.patch

package info (click to toggle)
ldapscripts 2.0.7-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 492 kB
  • ctags: 21
  • sloc: sh: 676; makefile: 167
file content (27 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
From: Alexander Gerasiov <gq@debian.org>
Subject: Use more secure tempfile creation
 Upstream uses buggy-way to create temp files. It is vulnerable to several
 attack technics. But he likes it, because of portablity.
 As we have mktemp(1) here in Debian, we will use it.
Forwarded: not-needed

--- a/lib/runtime
+++ b/lib/runtime
@@ -163,15 +163,10 @@
 mktempf () {
   # Avoid creating two temporary files (must have been released before)
   [ -n "$_TMPFILE" ] && end_die "Error allocating temporary file $_TMPFILE"
-  # Name temp file
-  _TMPFILE="$TMPDIR/$(basename $0).$(date '+%Y%m%d-%H%M%S').$$.$(head -c4 /dev/random | od -t u4 | head -n 1 | awk '{print $2}')"
+  # Create temp file
+  _TMPFILE="$(mktemp -p $TMPDIR "$(basename "$0").$(date '+%Y%m%d-%H%M%S').XXXXXX")"
   # Catch CTRL-C to remove $_TMPFILE
   trap 'rm -f "$_TMPFILE" 2>/dev/null ; end_die "Interrupted - Removing temporary file $_TMPFILE"' 2
-  # Create temp file
-  _TMPMASK=$(umask)
-  umask 0077
-  touch "$_TMPFILE" 2>/dev/null || end_die "Error creating temporary file $_TMPFILE"
-  umask "$_TMPMASK"
 }
 
 # Releases a previously allocated temporary file