bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: If $HISTFILE is set to /dev/null and you execute more commands than


From: Jonathan Hankins
Subject: Re: If $HISTFILE is set to /dev/null and you execute more commands than $HISTFILESIZE, /dev/null is deleted.
Date: Fri, 30 Jan 2015 13:09:18 -0600

A test with the POSIX S_ISREG macro on HISTFILE will determine if it, or the file it points to in the case of a symlink, is a regular file.

Just looked through the source, and it looks like general.c:file_exists() does not do any special handling of non-regular files, and lib/readline/histfile.c:history_do_write() calls open() and rename() on HISTFILE without checking if it is a non-regular file, which I imagine could lead to various "bad things" in the case of pipes, char and block devices, etc. such as what the OP pointed about about "/dev/null".

I haven't verified, but I think it also will not dereference links and may potentially be made to clobber or otherwise mess with files ending in hyphen (/etc/shadow-, /etc/passwd- and /etc/group- come to mind) because of the way lib/readline/histfile.c:history_backupfile() constructs the backup file name.  Someone with more knowledge than myself might want to look at this closer.  It seems like it might be a vector for abuse.

-Jonathan Hankins

On Fri, Jan 30, 2015 at 9:06 AM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
On Fri, Jan 30, 2015 at 09:58:43AM -0500, Chet Ramey wrote:
> On 1/30/15 4:36 AM, crocket wrote:
> > It turns out that tramp on emacs 24.4 sets $HISTFILE to /dev/null and
> > makes bash delete /dev/null when I kill emacs.
> >
> > When /dev/null is not a character device but a regular file, a lot of
> > programs freeze.
>
> This indicates a permissions or file system problem.

My guess was that (s)he's running bash as root, which accounts for the
ability to delete /dev/null and recreate it as an ordinary file.




--
------------------------------------------------------------------------
Jonathan Hankins    Homewood City Schools

The simplest thought, like the concept of the number one,
has an elaborate logical underpinning. - Carl Sagan

jhankins@homewood.k12.al.us
------------------------------------------------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]