# HG changeset patch # User al # Date 1353449789 0 # Node ID 3397976a029bdff2b3f74e7f7f12e9432485fabf # Parent 701e78689c075c0b729a02bba01ec50a2526001e stream ftp: readline: Always initialize output parameter buf Only exception if passed parameter max is less than or equal to zero. That cannot happen with the current code. Additionally change readresp function to always copy the first response line if the parameter rsp is non-NULL. This fixes some error reporting that used uninitialized stack arrays. diff -r 701e78689c07 -r 3397976a029b stream/stream_ftp.c --- a/stream/stream_ftp.c Tue Nov 20 22:13:57 2012 +0000 +++ b/stream/stream_ftp.c Tue Nov 20 22:16:29 2012 +0000 @@ -105,6 +105,9 @@ /* * read a line of text * + * 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. + * * return -1 on error or bytecount */ static int readline(char *buf,int max,struct stream_priv_s *ctl) @@ -113,6 +116,11 @@ char *end,*bp=buf; int eof = 0; + if (max <= 0) { + return -1; + } + *bp = '\0'; + do { if (ctl->cavail > 0) { x = FFMIN(ctl->cavail, max-1); @@ -181,13 +189,14 @@ { static char response[256]; char match[5]; - int r; + int r, len; - if (readline(response,256,ctl) == -1) + len = readline(response,256,ctl); + if (rsp) strcpy(rsp,response); + if (len == -1) return 0; r = atoi(response)/100; - if(rsp) strcpy(rsp,response); mp_msg(MSGT_STREAM,MSGL_V, "[ftp] < %s",response);