# HG changeset patch # User al # Date 1353449905 0 # Node ID 85003f7fa6212bdef0f1144c0d3eee1e7c2a8a4a # Parent 3397976a029bdff2b3f74e7f7f12e9432485fabf stream ftp: readline: Always try to read complete lines If there is not enough space in the provided line buffer just skip the remaining bytes until reaching EOL. Usually we are only interested in the first 5 characters and for everything else the (on-stack) response buffer should still be big enough. diff -r 3397976a029b -r 85003f7fa621 stream/stream_ftp.c --- a/stream/stream_ftp.c Tue Nov 20 22:16:29 2012 +0000 +++ b/stream/stream_ftp.c Tue Nov 20 22:18:25 2012 +0000 @@ -105,6 +105,11 @@ /* * read a line of text * + * If the line is too long to fit in the buffer, provided via parameters + * buf and max, the remaining characters are skipped. So the next call to + * this function is synchronized to the start of the following response + * line. + * * The parameter buf will always be initialized as long as max is bigger * then 1. If nothing is read it will contain an empty string. * @@ -144,8 +149,18 @@ } } if (max == 1) { - *buf = '\0'; - break; + char *q = memchr(ctl->cget, '\n', ctl->cavail); + + if (q) { // found EOL: update state and return + ++q; + ctl->cavail -= q - ctl->cget; + ctl->cget = q; + + break; + } + + // receive more data to find end of current line + ctl->cget = ctl->cput; } if (ctl->cput == ctl->cget) { ctl->cput = ctl->cget = ctl->buf;