History log of /netbsd-src/lib/libedit/read.c (Results 1 – 25 of 109)
Revision Date Author Comments
# 2cf0b469 03-Jan-2025 rillig <rillig@NetBSD.org>

libedit: remove redundant break statements after EL_ABORT


# 21a4b1cc 30-Oct-2022 christos <christos@NetBSD.org>

improvements in malloc/free handling.


# da69b70b 15-Aug-2021 christos <christos@NetBSD.org>

Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREA

Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.

show more ...


# 113f06a3 23-Jul-2019 christos <christos@NetBSD.org>

PR/54399: Sören Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix reallo

PR/54399: Sören Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.

show more ...


# e9933f92 25-Nov-2018 christos <christos@NetBSD.org>

From Yuichiro Naito (FreeBSD):

hrs@ says that
(cbp >= MB_LEN_MAX) condition is necessary for checking invalid
byte sequences. If malicious input was given, libedit would read
byte sequences forever.


# 18bb6ea4 18-Nov-2018 christos <christos@NetBSD.org>

Remove utf-8 requirement (Yuichiro NAITO)


# bec29a07 27-Jun-2017 christos <christos@NetBSD.org>

remove unused variable


# 3d8a0ad9 11-Dec-2016 christos <christos@NetBSD.org>

PR/51706: Amir Plivatsky: Fix memory leak


# d8509bf6 25-May-2016 christos <christos@NetBSD.org>

abstract read code to a single function (Ingo Schwarze)


# fa7ab2f9 24-May-2016 christos <christos@NetBSD.org>

el_map.alt can't be NULL here (Ingo Schwarze)


# 6eacc2db 24-May-2016 christos <christos@NetBSD.org>

remove debug read (Ingo Schwarze)


# 0a374fd7 24-May-2016 christos <christos@NetBSD.org>

From Ingo Schwarze:

Reduce obfuscation of errno handling. There is only one purpose
non-local errno handling is needed for: Inside el_wgets(), several
functions call down indirectly to el_wgetc(),

From Ingo Schwarze:

Reduce obfuscation of errno handling. There is only one purpose
non-local errno handling is needed for: Inside el_wgets(), several
functions call down indirectly to el_wgetc(), many of them via the
dispatch table. When el_wgetc() fails, it does properly report
failure, but then various cleanup is done which may clobber errno.
But when returning due to failure, el_wgets() wants to have errno
set to the reason of the original read failure, not to the reason
of some subsequent failure of some cleanup operation. So el_wgetc()
needs to save errno, and if it's non-zero, el_wgets() needs to
restore it on failure.

This core logic is currently obscured by the fact that el_errno
is set and inspected at some additional places where it isn't needed.
Besides, since el_wgetc() and and el_wgets() are both in read.c,
el_errno does not need to be in struct editline, it can and should
be local to read.c in struct el_read_t.

Let's look at what can be simplified.

1. keymacro_get() abuses el_errno instead of having a proper
error return code. Adding that error return code is easy
because node_trav() already detects the condition and an
adequate code is already defined. Returning it, testing
for it in read_getcmd(), and returning with error from there
removes the need to inspect el_errno from el_wgets() after
calling read_getcmd().
Note that resetting lastchar and cursor and clearing buffer[0]
is irrelevant. The code returns from el_wgets() right afterwards.
Outside el_wgets(), these variables are no longer relevant.
When el_wgets() is called the next time, it will call ch_reset()
anyway, resetting the two pointers. And as long as lastchar
points to the beginning of the buffer, the contents of the
buffer won't be used for anything.

2. read_getcmd() doesn't need to set el_errno again after el_wgetc()
failure since el_wgetc() already did so. While here, remove
the silly "if EOF or error" comments from the el_wgetc()
return value tests. It's a public interface documented in a
manual, so people working on the implementation can obviously
be expected to know how it works. It's a case of

count++; /* Increment count. */

3. In the two code paths of el_wgets() that lead up to "goto noedit",
there is no need to save the errno because nothing that might
change it happens before returning.

For clarity, since el_wgets() is the function restoring the errno,
also move initializing it to the same function.

Finally, note that restoring errno when the saved value is zero is
wrong. No library code is ever allowed to clear a previously set
value of errno. Only application programs are allowed to do that,
and even they usually don't need to do so, except when using certain
ill-designed interfaces like strtol(3).

I tested that the behaviour remains sane in the following cases,
all during execution of el_wgets(3) and with a signal handler
for USR1 installed without SA_RESTART.

* Enter some text and maybe move around a bit.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press Ctrl-V to activate ed-quoted-insert.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
ed_quoted_insert() returns ed_end_of_file(), i.e. CC_EOF,
and el_wgets() returns 0.

* Press a key starting a keyboard macro.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press : to enter builtin command mode.
Start typing a command.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now c_gets() returns -1, ed_command() beeps and returns CC_REFRESH,
and el_wgets() resumes operation as it should.

I also tested with "el_set(el, EL_EDITMODE, 0)", and it returns
the right value and sets errno correctly.

show more ...


# bb64d9f1 22-May-2016 christos <christos@NetBSD.org>

Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the ma

Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze

show more ...


# a2d6b270 09-May-2016 christos <christos@NetBSD.org>

s/protected/libedit_private/g


# 1364b603 19-Apr-2016 christos <christos@NetBSD.org>

From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "rea

From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "read.h" everywhere, but only in the two files
needing access to el_read, read.c and el.c.
- To functions that don't need more, pass the struct el_read_t *
rather than the full EditLine *.
- Of course, that means that read_init() can now fail from
memory exhaustion, but it's easy to clean up after that.

show more ...


# 4fc1f47d 18-Apr-2016 christos <christos@NetBSD.org>

From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it

From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.

show more ...


# 20d5bea3 12-Apr-2016 christos <christos@NetBSD.org>

FIONREAD takes int as an argument (Ingo Schwarze)


# 985c823c 12-Apr-2016 christos <christos@NetBSD.org>

From Ingo Schwarze:

* Delete the stubs of the XK_EXE mechanism that was never implemented.
From a security, stability, and simplicity perspective, i would
consider implementing it a truly ter

From Ingo Schwarze:

* Delete the stubs of the XK_EXE mechanism that was never implemented.
From a security, stability, and simplicity perspective, i would
consider implementing it a truly terrible idea, so let's better
get rid of it.

* Do not use the local variable "num" in el_wgets() alternately for
two completely different purposes. Only use it for the number
of characters read, as stated in the comment (or -1 as long as
that number is still unknown), not for the (more or less boolean)
return value of read_getcmd(). Actually, there is no need at
all to save the latter return value after testing it once.

* The function read_getcmd() has very unusual return values:
It returns -1 for success and 0 for EOF/error. Switch that around
to 0 for success and -1 for EOF/error to be less confusing, and
get rid of the OKCMD preprocessor macro.

* Get rid of one #ifdef section in el_wgets() by using
el->el_chared.c_macro directly at the only place
where it is used.

* Delete the unused MIN() macro.

show more ...


# 469d44f8 11-Apr-2016 christos <christos@NetBSD.org>

Get rid of private/public; keep protected (Ingo Schwarze)


# 0594af80 11-Apr-2016 christos <christos@NetBSD.org>

Char -> wchar_t from Ingo Schwarze.


# 0aefc7f9 11-Apr-2016 christos <christos@NetBSD.org>

more macro WIDECHAR undoing from Ingo Schwarze.


# fcf85103 09-Apr-2016 christos <christos@NetBSD.org>

More WIDECHAR elimination (Ingo Schwarze)


# 4e541d85 23-Mar-2016 christos <christos@NetBSD.org>

Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)


# d784c575 02-Mar-2016 christos <christos@NetBSD.org>

PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.


# fe2cf455 24-Feb-2016 christos <christos@NetBSD.org>

Tuck in mbstate_t to the wide char version only to avoid exposing the zeroing
hack and doing it in the narrow case.


12345