Home | History | Annotate | Download | only in libedit
History log of /src/lib/libedit/history.c
RevisionDateAuthorComments
 1.64  11-Jul-2024  kre Don't fchmod(fileno(fp), ...) in history_save_fp().

There are two reasons for this, first, the permissions of the history
file should be able to be set by the user, not forced to 0600 every
time the history file is overwritten (or appended to).

And more importantly, the fp used for fileno(fp) might have come
from fmemopen() or funopen() (etc) - none of which put a file
descriptor in the "fd" field (ie: fileno(fp) == -1).

To compensate for that, when a history file is opened (in history_save())
set the default permissions then - if the file is actually created.
As fopen() cannot do that (it simply uses 0666&~umask) create the
(normal type) of fp using (approximately) fdopen(open(...), ...)
where the open supplies the 0600 default permissions that are
desired here (which might still be restricted even more by the
umask). Callers using history(...,H_SAVE_FP,...) or
history(...,H_NSAVE_FP,...) now need to look after any permission
setting required themselves (but as the doc says absolutely
nothing about that, one way or the other, what happens in this
area has always been unspecified, and still is)

One "feature" of the fchmod() method is lost here - apart from forcing
the 0600 permissions (which isn't really desirable) that fchmod()
would also have failed if the current (effective) uid is not the owner of
the history file (or root). If that is required, a test for it could
be added later - the effect would be as it has always been, the file
named must have been writable (or its directory writable if the file
did not exist) the open would occur (potentially truncating the file)
after which the fchmod() would be attempted, possibly failing, and if
so, never writing anything. Any new uid test would work the same way.

OK christos@
 1.63  08-Oct-2019  christos Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
 1.62  13-Sep-2018  kre Fix editing mistake, remove ) from func call that is now gone.
 1.61  13-Sep-2018  christos more efficient to use decode_result :-) Pointed out by kre@
 1.60  12-Sep-2018  christos PR/53597: Yasuhiro Horimoto: Avoid segmentation fault in bad history file.
 1.59  23-Dec-2017  uwe branches: 1.59.2; 1.59.4;
The order in which the arguments to a function are evaluated is
undefined, so don't use va_arg() twice.

PR lib/52849
 1.58  01-Sep-2017  christos PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.57  11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.56  11-Apr-2016  christos chartype cleanups from Ingo Schwarze:

- The file tokenizer.c no longer uses chartype.h,
so don't include the header.

- The dummy definitions of ct_{de,en}code_string() for the
NARROWCHAR case are only used in history.c, so move them there.

- Now the whole content of chartype.h is for the wide character
case only. So remove the NARROWCHAR ifdef and include the
header only in the wide character case.

- In chartype.h, move ct_encode_char() below the comment explaining it.

- No more need for underscores before ct_{de,en}code_string().

- Make the conversion buffer resize functions private.
They are only called from the decoding and encoding functions
inside chartype.c, and no need can possibly arise to call them
from anywhere else.
 1.55  11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.54  11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.53  23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.52  17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.51  15-Feb-2016  christos Don't free getline memory (Ingo Schwarze).
 1.50  15-Feb-2016  christos Use getline for better portability.
 1.49  15-Feb-2016  christos Change the test for the size of encoded buffer to include the NULL, from
OpenBSD; no functional change.
 1.48  15-Feb-2016  christos Use fparseln to avoid newline hacks.
 1.47  11-May-2014  christos Add a history function that takes a FILE pointer; needed for Capsicum.
From Eitan Adler
 1.46  18-Nov-2011  christos branches: 1.46.6; 1.46.16;
Add coverity annotations about unreachable code (Kamil Dudka)
 1.45  29-Jul-2011  christos branches: 1.45.2;
pass -Wconversion
 1.44  29-Jul-2011  christos - fix unused params
- unconditionalize vis.h
 1.43  29-Jul-2011  christos KNF return (\1); -> return \1;
 1.42  28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.41  28-Jul-2011  christos include vis.h from dot.
 1.40  27-Jul-2011  christos fix narrow compilation
 1.39  27-Jul-2011  christos - don't leave cursor dangling on memory failure or after clearing the list
- compute the string length to be strvis'ed after the string is encoded
 1.38  16-Jan-2011  christos off by one in fetching history data. From: Gerry Swislow
 1.37  03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.36  30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.35  30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.34  07-Sep-2009  christos apply apple patches from:
http://opensource.apple.com/source/libedit/libedit-11/patches/
 1.33  06-Feb-2009  sketch Plug memory leak, from MySQL.
 1.32  28-Sep-2006  christos Fix memory leak found by valgrind (Julien Torres)
 1.31  01-Aug-2005  christos Don't forget to initialize h_del; from Julien Torres.
 1.30  14-Jul-2005  christos PR/30747: David N. Williams: libedit is missing remove_history()
Added, please test.
 1.29  06-Jul-2005  christos Fix memory leaks found by valgrind. From Julien Torres
 1.28  27-Nov-2004  christos PR/26785: Jess Thrysoee: libedit - H_NEXT and H_PREV shifts cursor on failure
 1.27  24-Aug-2004  christos make sure that we round up to 1K.
 1.26  20-Aug-2004  christos PR/26725: Sergey S. Kostyliov: Typo in libedit, possible buffer overflow in src/lib/libedit/history.c:history_save()
 1.25  18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.24  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.23  19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.22  21-Jan-2003  christos Add a uniquefier for the history function.
 1.21  27-Oct-2002  christos don't crash in memory shortage conditions.
 1.20  13-Oct-2002  christos write the vis(3) converted string into the file, not the original one.
Noted by Tim Robbins. Hi luke!
 1.19  18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.18  29-Sep-2001  jdolecek history_def_enter: fix off-by-one mistake in delete condition (the behaviour
to keep at least one entry on the history list is retained)
This fixes lib/9704 by Phil Nelson.
 1.17  20-Mar-2001  christos chmod the history file to 600 so that only the owner can read it.
[inspired by the openbsd fix to readline]
 1.16  04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.15  29-Aug-2000  lukem history_def_set has a `const int' as a third arg, not an `int'.
picked up by the ultrix compiler, reported by simonb@ ...
 1.14  02-Jul-1999  simonb More trailing white space.
 1.13  06-Mar-1999  mycroft Add missing , in he_errlist[] initializer. Yay lint.
 1.12  05-Feb-1999  christos Encode the history lines using strvis() before saving it. Fixes gdb history
problem with missing newlines.
 1.11  12-Dec-1998  christos - missing error message from array could cause core dump
- delint
 1.10  03-Dec-1998  cgd per e-mail with christos: history_next_event() should return -1, not NULL,
in case of error, just like history_prev_event() does.
 1.9  20-May-1998  christos Add H_APPEND to simplify the interface.
 1.8  20-May-1998  christos Add a function to be able to set the cursor to a given event number.
 1.7  14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.6  06-Jul-1997  christos Fix compiler warnings.
 1.5  11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.4  23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.3  11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2  15-Oct-1995  christos Added history load and save to file functions.
 1.1  06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1  06-May-1994  cgd libedit!
 1.45.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.2.1  17-Apr-2012  yamt sync with head
 1.46.16.1  10-Aug-2014  tls Rebase.
 1.46.6.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.4.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.59.4.1  10-Jun-2019  christos Sync with HEAD
 1.59.2.1  30-Sep-2018  pgoyette Ssync with HEAD

RSS XML Feed