[MPlayer-dev-eng] [PATCHv2 2/8] stream ftp: readline: Always initialize output parameter buf

Alexander Strasser eclipse7 at gmx.net
Sat Nov 17 01:01:47 CET 2012


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.

Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
 stream/stream_ftp.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/stream/stream_ftp.c b/stream/stream_ftp.c
index 6874e7b..4dd48b7 100644
--- a/stream/stream_ftp.c
+++ b/stream/stream_ftp.c
@@ -105,6 +105,9 @@ static int fd_can_read(int fd,int timeout) {
 /*
  * 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 @@ static int readline(char *buf,int max,struct stream_priv_s *ctl)
     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 int readresp(struct stream_priv_s* ctl,char* rsp)
 {
     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);
 
-- 
1.7.10.2.552.gaa3bb87


More information about the MPlayer-dev-eng mailing list