From b1ea038d4da56a912c3c84f304727f6834716739 Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 16 Dec 1996 16:53:41 +0000 Subject: [PATCH] strncat botches --- lib/libtermlib/fillcap.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/libtermlib/fillcap.c b/lib/libtermlib/fillcap.c index f868d4e5b40..5f364a5d006 100644 --- a/lib/libtermlib/fillcap.c +++ b/lib/libtermlib/fillcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fillcap.c,v 1.2 1996/08/27 03:32:32 tholo Exp $ */ +/* $OpenBSD: fillcap.c,v 1.3 1996/12/16 16:53:41 deraadt Exp $ */ /* * Copyright (c) 1996 SigmaSoft, Th. Lockert @@ -31,7 +31,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fillcap.c,v 1.2 1996/08/27 03:32:32 tholo Exp $"; +static char rcsid[] = "$OpenBSD: fillcap.c,v 1.3 1996/12/16 16:53:41 deraadt Exp $"; #endif #include @@ -84,18 +84,17 @@ _ti_fillcap(term) } else if (carriage_return != NULL && carriage_return_delay <= 0) { if (linefeed_if_not_lf != NULL) { - strncpy(buf, carriage_return, sizeof(buf) >> 1); - buf[sizeof(buf) >> 1] = '\0'; - strncat(buf, linefeed_if_not_lf, sizeof(buf) - 1); + strncpy(buf, carriage_return, (sizeof(buf) >> 1) -1); + buf[(sizeof(buf) >> 1) -1] = '\0'; + strncat(buf, linefeed_if_not_lf, sizeof(buf) - strlen(buf)); } else if (new_line_delay > 0) sprintf(buf, "%s\n$<%d>", carriage_return, new_line_delay); else { strncpy(buf, carriage_return, sizeof(buf) >> 1); - buf[sizeof(buf) >> 1] = '\0'; - strncat(buf, "\n", sizeof(buf) - 1); + buf[(sizeof(buf) >> 1) - 1] = '\0'; + strncat(buf, "\n", sizeof(buf) - strlen(buf)); } - buf[sizeof(buf) - 1] = '\0'; newline = strdup(buf); } if (return_does_clr_eol || no_correctly_working_cr) { -- 2.20.1