svn commit: r290065 - head/lib/libedit
Jilles Tjoelker
jilles at FreeBSD.org
Tue Oct 27 21:16:31 UTC 2015
Author: jilles
Date: Tue Oct 27 21:16:29 2015
New Revision: 290065
URL: https://svnweb.freebsd.org/changeset/base/290065
Log:
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)
Modified:
head/lib/libedit/vi.c
Modified: head/lib/libedit/vi.c
==============================================================================
--- head/lib/libedit/vi.c Tue Oct 27 21:08:46 2015 (r290064)
+++ head/lib/libedit/vi.c Tue Oct 27 21:16:29 2015 (r290065)
@@ -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 __attrib
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
More information about the svn-src-all
mailing list