From 34c5d18ff489821d7b917fcdf03b4c6494724233 Mon Sep 17 00:00:00 2001 From: Moritz Jodeit Date: Sat, 13 Sep 2008 12:04:50 +0000 Subject: Fix minor bug in the previous commit, which could hang the current session, when the last character of an overly long line was a newline character. Additionally reply with 500 "Command too long" for commands, which are too large. Issue found and proposed fix by Luke Mewburn . ok millert@ --- libexec/ftpd/ftpcmd.y | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libexec/ftpd/ftpcmd.y b/libexec/ftpd/ftpcmd.y index 1fda0525032..bf62735a8b5 100644 --- a/libexec/ftpd/ftpcmd.y +++ b/libexec/ftpd/ftpcmd.y @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpcmd.y,v 1.51 2008/09/12 16:12:08 moritz Exp $ */ +/* $OpenBSD: ftpcmd.y,v 1.52 2008/09/13 12:04:49 moritz Exp $ */ /* $NetBSD: ftpcmd.y,v 1.7 1996/04/08 19:03:11 jtc Exp $ */ /* @@ -44,7 +44,7 @@ static const char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94"; #else static const char rcsid[] = - "$OpenBSD: ftpcmd.y,v 1.51 2008/09/12 16:12:08 moritz Exp $"; + "$OpenBSD: ftpcmd.y,v 1.52 2008/09/13 12:04:49 moritz Exp $"; #endif #endif /* not lint */ @@ -1144,7 +1144,7 @@ getline(s, n, iop) * This prevents the command to be split up into * multiple commands. */ - while ((c = getc(iop)) != EOF && c != '\n') + while (c != '\n' && (c = getc(iop)) != EOF) ; return (-2); } @@ -1209,8 +1209,9 @@ yylex() reply(221, "You could at least say goodbye."); dologout(0); } else if (n == -2) { - /* Ignore truncated command */ - break; + reply(500, "Command too long."); + alarm(0); + continue; } (void) alarm(0); if ((cp = strchr(cbuf, '\r'))) { -- cgit v1.2.3