summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorasou <asou@cvs.openbsd.org>2019-09-04 00:00:50 +0000
committerasou <asou@cvs.openbsd.org>2019-09-04 00:00:50 +0000
commitb057b098dbde8f6dc9ed35f28bb60ca99eafaeda (patch)
tree7ca99fc84fb211bf6c56ad6ffd635ece09306758 /lib
parent10c59997c16d22440b91eb1d98b28ca299311815 (diff)
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@
Diffstat (limited to 'lib')
-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