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

Alexander Strasser eclipse7 at gmx.net
Sun Nov 11 22:00:59 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 0bb0711..333c133 100644
--- a/stream/stream_ftp.c
+++ b/stream/stream_ftp.c
@@ -104,6 +104,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)
@@ -112,6 +115,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 = (max > ctl->cavail) ? ctl->cavail : max-1;
@@ -180,13 +188,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