bin/165120: ed and sed - tmp file handling - security and location
grarpamp at gmail.com
Tue Feb 14 01:10:15 UTC 2012
>Synopsis: ed and sed - tmp file handling - security and location
>Arrival-Date: Tue Feb 14 01:10:14 UTC 2012
# /bin/ed has no means to relocate its temp file.
Absent other administrative solutions, this often leads
to a full /tmp.
# /usr/bin/sed has legacy/poor temp file handling.
Should be updated to use mkstemp(3) so as to be more
secure and therefore less clobberish.
Fix for both (add all three):
a) Add environment: TMPDIR
b) Add argument: -t <tmpdir>
Takes precedence over environment.
c) Change the default to: mkstemp(realpath(<file>.XXXXXX))
The directory that the file being edited resides in, and is
naturally expected to be writable and have sufficient free
space. Make tmp file named after <file> if possible so as
to be recognizable if crash cleanup is needed.
## line no's are for RELENG_8, topic applies to 8/9/HEAD
buf.c:191:char sfn = ""; /* scratch file name */
buf.c:202: strcpy(sfn, "/tmp/ed.XXXXXX");
buf.c:203: if ((fd = mkstemp(sfn)) == -1 ||
main.c:114:static char tmpfname[PATH_MAX]; /* Temporary file name (for in-place editing) */
main.c:398: len = snprintf(tmpfname, sizeof(tmpfname),
main.c:399: "%s/.!%ld!%s", dirname(fname), (long)getpid(),
Have space contention in /tmp.
Have security race or filename collision.
More information about the freebsd-bugs