summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormestre <mestre@openbsd.org>2017-11-26 09:59:41 +0000
committermestre <mestre@openbsd.org>2017-11-26 09:59:41 +0000
commit6e5d229df87092418a6945bc27fe284ac530cd29 (patch)
tree27b0e4e42ebb3fa7f7a30a04ddd11e8fd67d2fac
parent- pfctl fails to handle nested 'load anchor' properly (diff)
downloadwireguard-openbsd-6e5d229df87092418a6945bc27fe284ac530cd29.tar.xz
wireguard-openbsd-6e5d229df87092418a6945bc27fe284ac530cd29.zip
Fix segfault which could be triggered by deleting a backwards sentence if
cursor's current line was blank: echo "\nfoo" > a && vi a d( Same fix applied by rin@NetBSD, via nvi2 project. OK tom@ martijn@ tb@ millert@
-rw-r--r--usr.bin/vi/common/delete.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/usr.bin/vi/common/delete.c b/usr.bin/vi/common/delete.c
index 300dc088a7a..913e5292b80 100644
--- a/usr.bin/vi/common/delete.c
+++ b/usr.bin/vi/common/delete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: delete.c,v 1.11 2016/01/06 22:28:52 millert Exp $ */
+/* $OpenBSD: delete.c,v 1.12 2017/11/26 09:59:41 mestre Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -87,14 +87,16 @@ del(SCR *sp, MARK *fm, MARK *tm, int lmode)
if (tm->lno == fm->lno) {
if (db_get(sp, fm->lno, DBG_FATAL, &p, &len))
return (1);
- GET_SPACE_RET(sp, bp, blen, len);
- if (fm->cno != 0)
- memcpy(bp, p, fm->cno);
- memcpy(bp + fm->cno, p + (tm->cno + 1), len - (tm->cno + 1));
- if (db_set(sp, fm->lno,
- bp, len - ((tm->cno - fm->cno) + 1)))
- goto err;
- goto done;
+ if (len != 0) {
+ GET_SPACE_RET(sp, bp, blen, len);
+ if (fm->cno != 0)
+ memcpy(bp, p, fm->cno);
+ memcpy(bp + fm->cno, p + (tm->cno + 1), len - (tm->cno + 1));
+ if (db_set(sp, fm->lno,
+ bp, len - ((tm->cno - fm->cno) + 1)))
+ goto err;
+ goto done;
+ }
}
/*