changeset 35334:3397976a029b

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.
author al
date Tue, 20 Nov 2012 22:16:29 +0000
parents 701e78689c07
children 85003f7fa621
files stream/stream_ftp.c
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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);