aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2015-10-27 21:16:29 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2015-10-27 21:16:29 +0000
commitf1d04a25437977e20ab5a0ea87d2f617b2d1dead (patch)
tree88715f4dc46e9a2bbb22c3f95e213b7aa1b3a3a4 /lib
parent75908e8a2335a1f3c12308e159102e0086e33f6b (diff)
downloadsrc-f1d04a25437977e20ab5a0ea87d2f617b2d1dead.tar.gz
src-f1d04a25437977e20ab5a0ea87d2f617b2d1dead.zip
libedit: Use correct buffer lengths in vi mode v command.
Libedit's vi mode provides a v command to edit the current line in vi(1) (hard-coded to vi, in fact). When Unicode/wide character mode was added, this command started truncating and/or corrupting the edited text. This commit fixes v if the text fits into the buffer. If the text is longer, it is truncated. PR: 203743 Obtained from: NetBSD (originally submitted by me)
Notes
Notes: svn path=/head/; revision=290065
Diffstat (limited to 'lib')
-rw-r--r--lib/libedit/vi.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index dfd17e393559..0a426fd999d6 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */
+/* $NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $");
+__RCSID("$NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
@@ -1040,12 +1040,12 @@ vi_histedit(EditLine *el, Int 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 = ct_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