summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2003-07-09 13:15:32 +0000
committeryar <yar@FreeBSD.org>2003-07-09 13:15:32 +0000
commit94167f7347294d2c3505132eb74cae8b085df169 (patch)
treedf946080d08dcec7ed9e019f4f80ffabe460c224 /libexec
parentb42549b7254aedb1859a96651fcc28cfd9679459 (diff)
downloadFreeBSD-src-94167f7347294d2c3505132eb74cae8b085df169.zip
FreeBSD-src-94167f7347294d2c3505132eb74cae8b085df169.tar.gz
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
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ftpd/ftpcmd.y11
1 files changed, 7 insertions, 4 deletions
diff --git a/libexec/ftpd/ftpcmd.y b/libexec/ftpd/ftpcmd.y
index 4e8dfd5..3374439 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';
OpenPOWER on IntegriCloud