Skip to content

Commit

Permalink
Overlapping buffers in hist_word (#234)
Browse files Browse the repository at this point in the history
While experimenting with #233, a memory segmentation fault occurred.
A search of other emacs issues found a potential matching issue as
described in att#791. Also, a duplicate
PR of att#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.
  • Loading branch information
hyenias committed Mar 20, 2021
1 parent c33b75e commit 3abbb0d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cmd/ksh93/edit/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 3abbb0d

Please sign in to comment.