Commit Graph

810 Commits

Author SHA1 Message Date
christos
20fa0b90d9 PR/56147: Miroslav Lichvar: Avoid memory leak if strdup fails. 2021-05-05 14:49:59 +00:00
christos
ba06fc1c94 Only unescape when we are quoting and don't add a space if we are quoting
(we already did) (Piotr Stefaniak)
2021-03-28 13:39:39 +00:00
christos
1740d9142b document the flag 2021-03-28 13:38:10 +00:00
christos
b94551931c Pass the unescaped filename the the append function so it has to do less work
(for example it can call stat(2) directly (Piotr Stefaniak)
2021-03-28 13:33:54 +00:00
christos
65371df829 Add fn_complete2() that controls the quoting of the returned match.
Before it was based on the heuristic that we were not supplied an
attempted_completion_function, which worked well because programs
that supplied that function were not shells and did not want/understand
shell quoting. Recently though Piotr Stefaniak wanted to enhance command
completion for the Bourne Shell and this could benefit quoting the returned
command. This function adds an extra flags argument that controls that quoting.
2021-03-27 18:55:02 +00:00
christos
6953eca8c7 Fix numeric variable handling in settc (lyzliyuzhi at 163 dot com) 2020-07-10 20:34:24 +00:00
christos
58b288d88d use strlcpy() instead of strncpy() for gcc happiness 2020-05-31 23:24:23 +00:00
ryo
3bf82836bf patbuf must be updated if the length of patbuf is greater than or equal to 0. (that is always)
fix of r1.7 was incorrect.
2020-03-30 06:56:38 +00:00
ryo
1148c4261d fix build error with SDEBUG, MAP_DEBUG, DEBUG_REFRESH 2020-03-30 06:54:37 +00:00
abhinav
2d114b3c14 PR lib/54510 - when user supplied completion function is there,
don't unescape the string to be completed.
2020-01-05 07:12:05 +00:00
tih
52de8937af Summary: Remove over-simplified extraneous test
The file name matching code in libedit tries to adjust to the presence
of explicit " or ' characters in the input line, but tries too hard.
Remove a conditional that goes overboard, and causes the completion
code to fail if a quoted string is seen before the filename to be
expanded, as in

	  grep 'foo' bar<TAB>

Before this change, the above would not expand any possible
completions, even if they existed, because it would choose to look for
files whose names started with " bar".
2020-01-05 00:03:27 +00:00
christos
5e9cbb1173 When 'attempted_completion_function' non-NULL, with a 'single_match'
match, the expected space is not being added. Problem observed with
"chronyc" and "sqlite3" tab completion. That functionality got
moved to escape_filename() for the !attempted_completion_function
case, but the non-NULL 'attempted_completion_function' case must
also be handled. (Lonnie Abelbeck)
2019-12-10 19:42:09 +00:00
christos
b9ecc063aa PR/54654: Soren Tempel: Make sure el_cursor.v < el_terminal.t_size.v when
moving around.
2019-11-12 20:59:46 +00:00
mrg
de11d87641 introduce some common variables for use in GCC warning disables:
GCC_NO_FORMAT_TRUNCATION    -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION  -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW    -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE   -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints.  many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
2019-10-13 07:28:04 +00:00
christos
a47ebb18b3 add +1 to strlcpy's (Patrick Welche) 2019-10-09 14:31:07 +00:00
christos
3df2b62655 remore error(1) comment 2019-10-08 19:21:40 +00:00
christos
991f62167b Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
2019-10-08 19:17:57 +00:00
christos
a5a5a01f84 Fix type and remove cast (Yuichiro NAITO/FreeBSD). 2019-09-15 21:09:11 +00:00
abhinav
c3d00a7d30 PR lib/54510: Fix file completion inside quotes which broke in rev 1.53
While there also fix handling character appending in the file completions when
inside quotes. For example when inside a quote, if the completion is a directory then
append a '/' but don't close the quote. On the other hand when inside a quote if the
completion is a file name and it is the only match then we can close the quote.
2019-09-08 05:50:58 +00:00
christos
a909d35bd1 Increment offset when adding an element to history to keep it aligned with
the last element entered (Sandy Li Changqing)
2019-08-21 11:11:48 +00:00
christos
272963ae08 PR/54415: Ricky Zhou: libedit stats completions for non-file completions
Use the proper completion function and account for the character appended
by the function when computing the number of columns.
2019-07-28 09:27:29 +00:00
christos
755b70304b remove stray brace 2019-07-23 13:10:11 +00:00
christos
585d8da984 put the NULL check immediately after the allocation 2019-07-23 10:19:35 +00:00
christos
113f06a345 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.
2019-07-23 10:18:52 +00:00
christos
38ee0c7eda PR/54400: Sören Tempel: out-of-bounds read in libedit c_delbefore 2019-07-23 09:47:16 +00:00
christos
ac94b724c0 Add a comment explaining why we don't use DO here. Correct the attribution
on the previous patch: The patch was from Jordan Lewis and the report from
Raphael Poss.
2019-06-30 13:30:15 +00:00
christos
0d31660187 PR/54329: Raphael Ross: According to https://www.gnu.org/software/termutils/\
manual/termcap-1.3/html_chapter/termcap_4.html#SEC23 the cursor move multiple
escapes have undefined results when moving out of the screen. Stop using DO
to move down multiple lines and use a loop of newlines instead.
2019-06-29 21:35:09 +00:00
christos
037284caf7 PR/54281: Jonathan Perkins: NUL terminate rl_line_buffer on modification
to avoid completion leak.
2019-06-07 15:21:48 +00:00
christos
72dd3db662 PR/54280: rl_completer_quote_characters should be const for readline compat 2019-06-07 15:19:29 +00:00
christos
b8c4664f83 PR/54279: Jonathan Perkins: Ignore adjacent start/end prompt ignore. 2019-06-07 15:18:20 +00:00
christos
ef72f68d26 Follow the man page for EL_GETTC and not require a NULL terminated argument
list: https://reviews.llvm.org/D61191
2019-04-26 16:56:57 +00:00
abhinav
63147cb59c PR lib/54131 - declare the loop variable outside the for loop 2019-04-20 08:44:10 +00:00
christos
2f37aad7a2 PR/52359: Benjamin Lorenz: When resizing because of a signal save and restore
the cursor position, since it does not change.
2019-04-12 17:30:49 +00:00
christos
7512edc245 PR/54117: Paavo Helde: Fix memory overrun: Account for the closing quote
in memory allocation if quoted.
2019-04-12 15:12:29 +00:00
abhinav
c93cba3ab2 Perform quoting of filename completions when there are multiple matches as well
Quoting of special characters in filename completion was implemented for single match
case, this enables it for multiple matches as well. For example:

$ touch 'foo bar'
$ touch 'foo baz'
$ ls fo<TAB>
autocompletes to =>
$ ls foo\ ba
hitting <TAB> again shows:
foo bar foo baz

This required unescaping escape sequences generated during last completion
in order to find the word to complete.

While there, also update the test to include cases for multiple matches.

Reviewed by christos
2019-03-31 03:04:57 +00:00
abhinav
e09538bda2 Only quote the completion matches if we are doing filename completion
If the user supplies a value for the attempted_completion_function parameter
then we cannot be sure if the completion is for filename or something else, in such
a case don't attempt to quote the completion matches.

Reviewed by christos

This should address PR lib/54067
2019-03-24 16:42:49 +00:00
christos
52b10dfde0 PR/53983: Jonathan Perkins: Fix types for readline compatibility 2019-02-15 23:20:35 +00:00
christos
ccbb6255be PR/53981: Jonathan Perkins: history_list should null-terminate 2019-02-14 20:09:12 +00:00
christos
11e9eb638e PR/53856: F. Aragon: editline/libedit not prompting colors in readline mode 2019-01-10 18:41:56 +00:00
uwe
13b962ac1e Fix mis-applied change in previous. Don't increment r_oldcv twice.
PR lib/53803
2019-01-04 03:03:44 +00:00
christos
85390d7315 Add a couple more readline compat functions. 2018-12-02 16:58:13 +00:00
christos
f04c2e3e34 Fix off by one <tsahara at iij> 2018-11-29 03:10:20 +00:00
christos
e9933f923a 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.
2018-11-25 16:21:04 +00:00
christos
2cb4fa4296 From Yuichiro Naito (FreeBSD):
hrs@ says that wctomb(3) has an internal shift state,
if wctomb(3) is called outside of libedit,
the internal state can be changed and causes miscalculate multibyte size.

So in this part, wcrtomb(3) should be used.
wcrtomb(3) requires that shift state is given in the argument.
We always initialize the shift state in ct_enc_width() to keep independent
from outside of libedit.
2018-11-25 16:20:28 +00:00
christos
e06500e20d PR/53682: Jordan Lewis: use newlines instead of padded spaces when restoring
multi-line histories.
2018-11-24 12:17:35 +00:00
christos
e91c30539f fix compilation 2018-11-18 17:15:41 +00:00
christos
18bb6ea433 Remove utf-8 requirement (Yuichiro NAITO) 2018-11-18 17:09:39 +00:00
christos
b15150dc5e Apply revisions 1.21, 1.22 from OpenBSD:
In re_fastputc(), set lastline to the new line, not the previous
line so it gets initialized properly.  Fixes a crash in bc with
MALLOC_OPTIONS=UJ.  OK deraadt@, committing on behalf of yasuoka@

Initialize "old" screen buffer lines before use; otherwise, they would
never get NUL-terminated and cause read buffer overruns.
This fixes for example segfaults in sftp(1) that could be triggered
by typing in an extremely long string (more than one line - the longer,
the likelier to crash), then hitting backspace once.
Problem reported and patch OK'ed by sthen@.

XXX: pullup-8
2018-10-23 16:49:13 +00:00
kre
b8b0289d66 Fix editing mistake, remove ) from func call that is now gone. 2018-09-13 09:03:40 +00:00
christos
26f83385d3 more efficient to use decode_result :-) Pointed out by kre@ 2018-09-13 01:26:33 +00:00