diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-11-02 01:43:02 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-11-02 01:43:02 +0000 |
commit | 483854b412c06c0f061adb060bde17617770582a (patch) | |
tree | 01b23300f7a4fff8afa1b7357a0efbc18b0b5119 | |
parent | f5ab3890d163f50779cc310e2eb866c7a4d40e80 (diff) |
Add checks for fgets and properly overwrite newline.
Initial patch from Charles Longeau <chl at tuxfamily dot org>.
OK moritz@ and jaredy@.
-rw-r--r-- | usr.bin/ftp/cmds.c | 13 | ||||
-rw-r--r-- | usr.bin/ftp/util.c | 20 |
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) { |