From 3abbb0dcb5a527fa22f40d31d0ed5737d4dda101 Mon Sep 17 00:00:00 2001 From: hyenias <58673227+hyenias@users.noreply.github.com> Date: Sat, 20 Mar 2021 12:07:30 -0400 Subject: [PATCH] Overlapping buffers in hist_word (#234) While experimenting with #233, a memory segmentation fault occurred. A search of other emacs issues found a potential matching issue as described in https://github.com/att/ast/pull/791. Also, a duplicate PR of https://github.com/att/ast/pull/1489 was submitted. This commit backports that fix. src/cmd/ksh93/edit/history.c: hist_word(): - Switch from using strcpy to memmove as the two strings could overlap. --- src/cmd/ksh93/edit/history.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index 191f3469c..7d50ee072 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -1115,7 +1115,8 @@ char *hist_word(char *string,int size,int word) } *cp = 0; if(s1 != string) - strcpy(string,s1); + /* We can't use strcpy() because the two buffers may overlap. */ + memmove(string,s1,strlen(s1)+1); return(string); }