nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 7157f5a3ce7a89a020b67e079ef4941a1980a795
parent 5ca4e9f5b3d4ecf2cf645ddca0d13aea1a3445e7
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sat, 25 Jul 2020 13:19:19 +0200

tabbing: properly terminate the answer when the sole match is a folder

When there is just one match when <Tab> is pressed, and this match
is a directory, then a slash is added to 'shared', overwriting the
terminating NUL character.  So, strcpy() cannot be used for copying
this 'shared' string, but strncpy() is needed, and the result needs
to be NUL terminated afterward.

This fixes https://savannah.gnu.org/bugs/?58826.

Bug existed since commit b0f56398 from eleven days ago.

Diffstat:
Msrc/files.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/files.c b/src/files.c @@ -2566,7 +2566,8 @@ char *input_tab(char *morsel, size_t *place, void (*refresh_func)(void), bool *l /* If the matches have something in common, copy that part. */ if (common_len != *place) { morsel = charealloc(morsel, common_len + 1); - strcpy(morsel, shared); + strncpy(morsel, shared, common_len); + morsel[common_len] = '\0'; *place = common_len; } else if (num_matches == 1) beep();