summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasou <asou@openbsd.org>2019-09-04 00:00:49 +0000
committerasou <asou@openbsd.org>2019-09-04 00:00:49 +0000
commitf481be8c6a73f67c46d0409fa2a0ae816a1aec39 (patch)
treed2b0b3e8907c561e5a9b7d359228699781525673
parentless uses a correct raceless signal method of indicating signal events in (diff)
downloadwireguard-openbsd-f481be8c6a73f67c46d0409fa2a0ae816a1aec39.tar.xz
wireguard-openbsd-f481be8c6a73f67c46d0409fa2a0ae816a1aec39.zip
Correct the length of read from file, wide character buffer, add NUL
terminate to read buffer. This fix the bug that does not run input command entered by vi editor. This fix is come from NetBSD lib/libedit/vi.c 1.46 and 1.47. ok schwarze@ deraadt@
-rw-r--r--lib/libedit/vi.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index 8c12b16aaa4..2a3042e9561 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.27 2019/09/03 02:28:25 asou Exp $ */
+/* $OpenBSD: vi.c,v 1.28 2019/09/04 00:00:49 asou Exp $ */
/* $NetBSD: vi.c,v 1.33 2011/02/17 16:44:48 joerg Exp $ */
/*-
@@ -1058,12 +1058,12 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
while (waitpid(pid, &status, 0) != pid)
continue;
lseek(fd, (off_t)0, SEEK_SET);
- st = read(fd, cp, TMP_BUFSIZ);
+ st = read(fd, cp, TMP_BUFSIZ - 1);
if (st > 0) {
- len = (size_t)(el->el_line.lastchar -
- el->el_line.buffer);
+ cp[st] = '\0';
+ len = (size_t)(el->el_line.limit - el->el_line.buffer);
len = mbstowcs(el->el_line.buffer, cp, len);
- if (len > 0 && el->el_line.buffer[len -1] == '\n')
+ if (len > 0 && el->el_line.buffer[len - 1] == '\n')
--len;
}
else