summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/ftp/cmds.c13
-rw-r--r--usr.bin/ftp/util.c20
2 files changed, 20 insertions, 13 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;
}
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 12d1be4f7f6..17366d6b5d7 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.43 2006/05/16 23:43:16 ray Exp $ */
+/* $OpenBSD: util.c,v 1.44 2006/11/02 01:43:01 ray 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.43 2006/05/16 23:43:16 ray Exp $";
+static const char rcsid[] = "$OpenBSD: util.c,v 1.44 2006/11/02 01:43:01 ray Exp $";
#endif /* not lint and not SMALL */
/*
@@ -308,13 +308,15 @@ tryagain:
fprintf(ttyout, "Name (%s:%s): ", host, myname);
else
fprintf(ttyout, "Name (%s): ", host);
- *tmp = '\0';
- (void)fgets(tmp, sizeof(tmp) - 1, stdin);
- tmp[strlen(tmp) - 1] = '\0';
- if (*tmp == '\0')
- user = myname;
- else
- user = tmp;
+ user = myname;
+ if (fgets(tmp, sizeof(tmp) - 1, stdin) != NULL) {
+ char *p;
+
+ if ((p = strchr(tmp, '\n')) != NULL)
+ *p = '\0';
+ if (tmp[0] != '\0')
+ user = tmp;
+ }
}
n = command("USER %s", user);
if (n == CONTINUE) {