From 39b96ba75d7bfc29f121f222416f72ac1d94127b Mon Sep 17 00:00:00 2001 From: Yaroslav Tykhiy Date: Wed, 9 Jul 2003 13:15:32 +0000 Subject: [PATCH] Improve error handling in getline(): - always check the return value from getc(3) for EOF; - if the attempt to read the TELNET command byte has returned EOF, exit from the loop instead of using the EOF value as a normal character. MFC after: 1 week --- libexec/ftpd/ftpcmd.y | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libexec/ftpd/ftpcmd.y b/libexec/ftpd/ftpcmd.y index 4e8dfd528626..3374439814cc 100644 --- a/libexec/ftpd/ftpcmd.y +++ b/libexec/ftpd/ftpcmd.y @@ -1187,18 +1187,21 @@ getline(char *s, int n, FILE *iop) while ((c = getc(iop)) != EOF) { c &= 0377; if (c == IAC) { - if ((c = getc(iop)) != EOF) { + if ((c = getc(iop)) == EOF) + goto got_eof; c &= 0377; switch (c) { case WILL: case WONT: - c = getc(iop); + if ((c = getc(iop)) == EOF) + goto got_eof; printf("%c%c%c", IAC, DONT, 0377&c); (void) fflush(stdout); continue; case DO: case DONT: - c = getc(iop); + if ((c = getc(iop)) == EOF) + goto got_eof; printf("%c%c%c", IAC, WONT, 0377&c); (void) fflush(stdout); continue; @@ -1207,12 +1210,12 @@ getline(char *s, int n, FILE *iop) default: continue; /* ignore command */ } - } } *cs++ = c; if (--n <= 0 || c == '\n') break; } +got_eof: if (c == EOF && cs == s) return (NULL); *cs++ = '\0';