From 7157f5a3ce7a89a020b67e079ef4941a1980a795 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 25 Jul 2020 13:19:19 +0200 Subject: [PATCH] tabbing: properly terminate the answer when the sole match is a folder When there is just one match when 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. --- src/files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index 67886758..ac545539 100644 --- 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();