From 28816b14035bb08ad1d134a6d059b038e14eb7d8 Mon Sep 17 00:00:00 2001 From: Thierry Deval Date: Sat, 5 Apr 2003 00:43:21 +0000 Subject: strcpy/strcat -> strlcpy/strlcat ok tedu@, hints by deraadt@ and millert@ --- lib/libedit/history.c | 8 ++++---- lib/libedit/term.c | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'lib/libedit') diff --git a/lib/libedit/history.c b/lib/libedit/history.c index d6b9e745662..7ba8f0897b4 100644 --- a/lib/libedit/history.c +++ b/lib/libedit/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.7 2002/02/19 19:39:37 millert Exp $ */ +/* $OpenBSD: history.c,v 1.8 2003/04/05 00:43:20 tdeval Exp $ */ /* $NetBSD: history.c,v 1.5 1997/04/11 17:52:46 christos Exp $ */ /*- @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$OpenBSD: history.c,v 1.7 2002/02/19 19:39:37 millert Exp $"; +static char rcsid[] = "$OpenBSD: history.c,v 1.8 2003/04/05 00:43:20 tdeval Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -234,8 +234,8 @@ history_def_add(p, str) return (history_def_enter(p, str)); len = strlen(h->cursor->ev.str) + strlen(str) + 1; s = (char *) h_malloc(len); - (void)strcpy(s, h->cursor->ev.str); - (void)strcat(s, str); + (void)strlcpy(s, h->cursor->ev.str, len); + (void)strlcat(s, str, len); h_free((ptr_t) h->cursor->ev.str); h->cursor->ev.str = s; return &h->cursor->ev; diff --git a/lib/libedit/term.c b/lib/libedit/term.c index c516b8a3013..c69d2b5a1df 100644 --- a/lib/libedit/term.c +++ b/lib/libedit/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.7 2002/11/29 20:13:39 deraadt Exp $ */ +/* $OpenBSD: term.c,v 1.8 2003/04/05 00:43:20 tdeval Exp $ */ /* $NetBSD: term.c,v 1.8 1997/01/23 14:02:49 mrg Exp $ */ /*- @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)term.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$OpenBSD: term.c,v 1.7 2002/11/29 20:13:39 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: term.c,v 1.8 2003/04/05 00:43:20 tdeval Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -371,7 +371,7 @@ term_alloc(el, t, cap) * New string is shorter; no need to allocate space */ if (clen <= tlen) { - (void)strcpy(*str, cap); + (void)strlcpy(*str, cap, tlen + 1); return; } @@ -379,7 +379,8 @@ term_alloc(el, t, cap) * New string is longer; see if we have enough space to append */ if (el->el_term.t_loc + 3 < TC_BUFSIZE) { - (void)strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap); + tlen = TC_BUFSIZE - el->el_term.t_loc; + (void)strlcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap, tlen); el->el_term.t_loc += clen + 1; /* one for \0 */ return; } @@ -403,7 +404,8 @@ term_alloc(el, t, cap) (void)fprintf(el->el_errfile, "Out of termcap string space.\n"); return; } - (void)strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap); + tlen = TC_BUFSIZE - el->el_term.t_loc; + (void)strlcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap, tlen); el->el_term.t_loc += clen + 1; /* one for \0 */ return; } /* end term_alloc */ -- cgit v1.2.3