From a8ba60ecf20c221bd24ff666339eb5edcbbbac33 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 11 Sep 2007 15:47:18 +0000 Subject: use strcspn to properly overwrite '\n' in fgets returned buffer ok pyr@, ray@, millert@, moritz@, chl@ --- usr.bin/ftp/util.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'usr.bin/ftp/util.c') diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index c03a9034003..7ebe58a15de 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.46 2007/06/06 19:15:33 pyr Exp $ */ +/* $OpenBSD: util.c,v 1.47 2007/09/11 15:47:17 gilles Exp $ */ /* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */ /*- @@ -71,7 +71,7 @@ */ #if !defined(lint) && !defined(SMALL) -static const char rcsid[] = "$OpenBSD: util.c,v 1.46 2007/06/06 19:15:33 pyr Exp $"; +static const char rcsid[] = "$OpenBSD: util.c,v 1.47 2007/09/11 15:47:17 gilles Exp $"; #endif /* not lint and not SMALL */ /* @@ -312,10 +312,7 @@ tryagain: fprintf(ttyout, "Name (%s): ", host); user = myname; if (fgets(tmp, sizeof(tmp), stdin) != NULL) { - char *p; - - if ((p = strchr(tmp, '\n')) != NULL) - *p = '\0'; + tmp[strcspn(tmp, "\n")] = '\0'; if (tmp[0] != '\0') user = tmp; } @@ -469,8 +466,9 @@ remglob(char *argv[], int doswitch, char **errbuf) ftemp = NULL; return (NULL); } - if ((cp = strchr(buf, '\n')) != NULL) - *cp = '\0'; + + buf[strcspn(buf, "\n")] = '\0'; + return (buf); } -- cgit v1.2.3