summaryrefslogtreecommitdiff
path: root/usr.bin/vi/ex
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-08-18 20:35:14 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-08-18 20:35:14 +0000
commit5d9557b2e9034c3a49886cd1d8695a3f2b385df6 (patch)
treef8c5dabde65c675ffd665ba094eae541494e9571 /usr.bin/vi/ex
parent79195842d32568913ad91e673b5e6c24beef041d (diff)
Range check snprintf() return value
Diffstat (limited to 'usr.bin/vi/ex')
-rw-r--r--usr.bin/vi/ex/ex_print.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/usr.bin/vi/ex/ex_print.c b/usr.bin/vi/ex/ex_print.c
index f3af8a5ee98..b7a1327fc45 100644
--- a/usr.bin/vi/ex/ex_print.c
+++ b/usr.bin/vi/ex/ex_print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_print.c,v 1.3 2001/01/29 01:58:43 niklas Exp $ */
+/* $OpenBSD: ex_print.c,v 1.4 2001/08/18 20:35:13 millert Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -293,9 +293,12 @@ ex_printf(sp, fmt, va_alist)
#else
va_start(ap);
#endif
- exp->obp_len += n = vsnprintf(exp->obp + exp->obp_len,
+ n = vsnprintf(exp->obp + exp->obp_len,
sizeof(exp->obp) - exp->obp_len, fmt, ap);
va_end(ap);
+ if (n >= sizeof(exp->obp) - exp->obp_len)
+ n = sizeof(exp->obp) - exp->obp_len - 1;
+ exp->obp_len += n;
/* Flush when reach a <newline> or half the buffer. */
if (exp->obp[exp->obp_len - 1] == '\n' ||