diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2007-09-11 15:47:18 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2007-09-11 15:47:18 +0000 |
commit | a8ba60ecf20c221bd24ff666339eb5edcbbbac33 (patch) | |
tree | 650532cc79cb8294b5e7739a5b61676601594950 /usr.bin/ftp/util.c | |
parent | d0c98e555e46b02b8df61047ae1c820859b23e93 (diff) |
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
Diffstat (limited to 'usr.bin/ftp/util.c')
-rw-r--r-- | usr.bin/ftp/util.c | 14 |
1 files changed, 6 insertions, 8 deletions
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); } |