summaryrefslogtreecommitdiff
path: root/usr.bin/ftp/cmds.c
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-11-02 01:43:02 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-11-02 01:43:02 +0000
commit483854b412c06c0f061adb060bde17617770582a (patch)
tree01b23300f7a4fff8afa1b7357a0efbc18b0b5119 /usr.bin/ftp/cmds.c
parentf5ab3890d163f50779cc310e2eb866c7a4d40e80 (diff)
Add checks for fgets and properly overwrite newline.
Initial patch from Charles Longeau <chl at tuxfamily dot org>. OK moritz@ and jaredy@.
Diffstat (limited to 'usr.bin/ftp/cmds.c')
-rw-r--r--usr.bin/ftp/cmds.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index 5bfa2d34f04..f37acd35683 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmds.c,v 1.52 2006/05/19 04:05:35 ray Exp $ */
+/* $OpenBSD: cmds.c,v 1.53 2006/11/02 01:43:01 ray Exp $ */
/* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */
/*
@@ -60,7 +60,7 @@
*/
#if !defined(lint) && !defined(SMALL)
-static const char rcsid[] = "$OpenBSD: cmds.c,v 1.52 2006/05/19 04:05:35 ray Exp $";
+static const char rcsid[] = "$OpenBSD: cmds.c,v 1.53 2006/11/02 01:43:01 ray Exp $";
#endif /* not lint and not SMALL */
/*
@@ -1271,10 +1271,14 @@ user(int argc, char *argv[])
}
if (n == CONTINUE) {
if (argc < 4) {
+ char *p;
+
(void)fputs("Account: ", ttyout);
(void)fflush(ttyout);
- (void)fgets(acctname, sizeof(acctname) - 1, stdin);
- acctname[strlen(acctname) - 1] = '\0';
+ if (fgets(acctname, sizeof(acctname) - 1, stdin) == NULL)
+ goto fail;
+ if ((p = strchr(acctname, '\n')) != NULL)
+ *p = '\0';
argv[3] = acctname;
argc++;
}
@@ -1282,6 +1286,7 @@ user(int argc, char *argv[])
aflag++;
}
if (n != COMPLETE) {
+ fail:
fputs("Login failed.\n", ttyout);
return;
}