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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#! /bin/sh -e
## 01_buf.c-tmpfile.dpatch by ?? (Discovered by Alan Cox. Patch author forgotten, possibly Wichert Akkerman)
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Fix /tmp symlink vulnerability.
if [ $# -ne 1 ]; then
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
exit 1
fi
case "$1" in
-patch) patch -f --no-backup-if-mismatch -p1 < $0;;
-unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
*)
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
exit 1;;
esac
exit 0
--- ed-0.2.orig/buf.c
+++ ed-0.2/buf.c
@@ -194,8 +194,6 @@
extern int newline_added;
-char sfn[15] = ""; /* scratch file name */
-
/* open_sbuf: open scratch file */
int
open_sbuf ()
@@ -205,10 +203,9 @@
isbinary = newline_added = 0;
u = umask(077);
- strcpy (sfn, "/tmp/ed.XXXXXX");
- if (mktemp (sfn) == NULL || (sfp = fopen (sfn, "w+")) == NULL)
+ if ((sfp = tmpfile()) == NULL)
{
- fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
+ fprintf (stderr, "open_sbuf: tmpfile() failed with '%s'\n", strerror (errno));
sprintf (errmsg, "Cannot open temp file");
umask(u);
return ERR;
@@ -226,14 +223,14 @@
{
if (fclose (sfp) < 0)
{
- fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
+ fprintf (stderr, "close_sbuf: fclose on temporary file failed with '%s'.\n", strerror (errno));
sprintf (errmsg, "Cannot close temp file");
return ERR;
}
sfp = NULL;
- unlink (sfn);
}
sfseek = seek_write = 0;
+
return 0;
}
@@ -246,7 +243,6 @@
if (sfp)
{
fclose (sfp);
- unlink (sfn);
}
exit (n);
}
|