[MPlayer-cvslog] r35428 - trunk/stream/stream_ftp.c

al subversion at mplayerhq.hu
Tue Nov 20 23:16:29 CET 2012


Author: al
Date: Tue Nov 20 23:16:29 2012
New Revision: 35428

Log:
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.

Modified:
   trunk/stream/stream_ftp.c

Modified: trunk/stream/stream_ftp.c
==============================================================================
--- trunk/stream/stream_ftp.c	Tue Nov 20 23:13:57 2012	(r35427)
+++ trunk/stream/stream_ftp.c	Tue Nov 20 23:16:29 2012	(r35428)
@@ -105,6 +105,9 @@ static int fd_can_read(int fd,int timeou
 /*
  * 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,st
     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
 {
     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);
 


More information about the MPlayer-cvslog mailing list