unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* sh-tmp-file inserts unsafe code
@ 2005-10-09 15:30 Sven Joachim
  2005-10-10  4:14 ` Richard M. Stallman
  2005-10-10 17:46 ` Kevin Rodgers
  0 siblings, 2 replies; 16+ messages in thread
From: Sven Joachim @ 2005-10-09 15:30 UTC (permalink / raw)


The command `sh-tmp-file' (bound to `C-c C-t' in shell-script-mode)
inserts code to setup temporary file handling based on the script's
name and its pid at runtime.  E.g., for foo.sh:

TMP=${TMPDIR:-/tmp}/foo.sh.$$
trap "rm $TMP* 2>/dev/null" 0

Or for foo.csh:

set tmp = /tmp/foo.csh.$$
onintr exit

Such handling of temporary files used to be common practice, but it is
_unsafe_, exposing the user of the script to symlink attacks.  This is
especially bad if the script is to be run by the superuser, but even
an ordinary user could suffer data loss.  I think Emacs should not
encourage such dangerous coding practice.

How about rewriting sh-tmp-file so that it uses mktemp(1) to create
the temporary file?

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: sh-tmp-file inserts unsafe code
@ 2005-10-11 13:55 Sven Joachim
  0 siblings, 0 replies; 16+ messages in thread
From: Sven Joachim @ 2005-10-11 13:55 UTC (permalink / raw)
  Cc: emacs-devel

Kevin Rodgers wrote:
> What about those of us on systems that do not provide mktemp(1)?

> I'm running ksh 93 on Solaris 9.

You should install it from www.mktemp.org.
Does Sun provide mktemp in Solaris 10?

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: sh-tmp-file inserts unsafe code
@ 2005-10-12 16:19 Sven Joachim
  0 siblings, 0 replies; 16+ messages in thread
From: Sven Joachim @ 2005-10-12 16:19 UTC (permalink / raw)
  Cc: emacs-devel

Reiner Steib wrote:

> $ mktemp -t foo.sh.XXXXXXXXXX
> /tmp/foo.sh.XXXXXXXXXX.KnRhKukl
> $ uname -a
> FreeBSD x86-freebsd1 4.11-RELEASE FreeBSD 4.11-RELEASE #0: [...]
>
> $ mktemp -t foo.sh.XXXXXXXXXX
> bash: mktemp: command not found
> $ uname -a
> SunOS sparc-solaris1 5.9 Generic_112233-03 sun4u sparc SUNW,Ultra-60
>
> $ mktemp -t foo.sh.XXXXXXXXXX
> /tmp/foo.sh.XXXXgHaO1t
> $ uname -a
> SunOS wega 5.10 Generic_118822-02 sun4u sparc SUNW,Ultra-Enterprise Solaris
>
> $ mktemp -t foo.sh.XXXXXXXXXX
> /tmp/foo.sh.J7Wmqo2lpy
> $ uname -a
> Darwin ppc-osx2.[...] 6.8 Darwin Kernel Version 6.8: [...]
>
> HP-UX 10.20 also has maktemp, but doesn't support `-t':
>
> ,----[ mktemp(1) on HP-UX 10.20 ]
> |  SYNOPSIS
> |       mktemp [-c] [-d directory_name] [-p prefix]
> `----

Thank you.  That's quite a mess indeed. :-(
It confirms that portable scripts best start with

#!/usr/bin/perl

;-)

Cheers, Sven.

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: sh-tmp-file inserts unsafe code
@ 2005-10-12 19:23 Sven Joachim
  2005-10-13 17:26 ` Kevin Rodgers
  0 siblings, 1 reply; 16+ messages in thread
From: Sven Joachim @ 2005-10-12 19:23 UTC (permalink / raw)
  Cc: emacs-devel, reinersteib+gmane

Richard M. Stallman wrote:

> Nobody HAS to use that obscure feature of sh-script mode.

It's not _that_ obscure, it even has a menu entry.

> So it can use -t. If that doesn't work on your operating system,
> switch to GNU/Linux.

Incidentally, the systems where it does _not_ work are all propietary,
according to Reiner's message.  That may be no coincidence...

Cheers, Sven.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2005-10-13 17:26 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-09 15:30 sh-tmp-file inserts unsafe code Sven Joachim
2005-10-10  4:14 ` Richard M. Stallman
2005-10-10  8:20   ` Sven Joachim
2005-10-10 10:06     ` Emanuele Giaquinta
2005-10-10 15:10       ` Reiner Steib
2005-10-10 23:47       ` Richard M. Stallman
2005-10-11 13:53   ` Sven Joachim
     [not found]     ` <74205160510110729i683ad538xa6bdc6b76f131532@mail.gmail.com>
2005-10-11 14:41       ` Sven Joachim
2005-10-11 16:56         ` Reiner Steib
2005-10-12 16:24           ` Richard M. Stallman
2005-10-11 22:43     ` Richard M. Stallman
2005-10-10 17:46 ` Kevin Rodgers
  -- strict thread matches above, loose matches on Subject: below --
2005-10-11 13:55 Sven Joachim
2005-10-12 16:19 Sven Joachim
2005-10-12 19:23 Sven Joachim
2005-10-13 17:26 ` Kevin Rodgers

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).