comparison stream/stream_ftp.c @ 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
comparison
equal deleted inserted replaced
35333:701e78689c07 35334:3397976a029b
103 } 103 }
104 104
105 /* 105 /*
106 * read a line of text 106 * read a line of text
107 * 107 *
108 * The parameter buf will always be initialized as long as max is bigger
109 * then 1. If nothing is read it will contain an empty string.
110 *
108 * return -1 on error or bytecount 111 * return -1 on error or bytecount
109 */ 112 */
110 static int readline(char *buf,int max,struct stream_priv_s *ctl) 113 static int readline(char *buf,int max,struct stream_priv_s *ctl)
111 { 114 {
112 int x,retval = 0; 115 int x,retval = 0;
113 char *end,*bp=buf; 116 char *end,*bp=buf;
114 int eof = 0; 117 int eof = 0;
118
119 if (max <= 0) {
120 return -1;
121 }
122 *bp = '\0';
115 123
116 do { 124 do {
117 if (ctl->cavail > 0) { 125 if (ctl->cavail > 0) {
118 x = FFMIN(ctl->cavail, max-1); 126 x = FFMIN(ctl->cavail, max-1);
119 end = memccpy(bp,ctl->cget,'\n',x); 127 end = memccpy(bp,ctl->cget,'\n',x);
179 */ 187 */
180 static int readresp(struct stream_priv_s* ctl,char* rsp) 188 static int readresp(struct stream_priv_s* ctl,char* rsp)
181 { 189 {
182 static char response[256]; 190 static char response[256];
183 char match[5]; 191 char match[5];
184 int r; 192 int r, len;
185 193
186 if (readline(response,256,ctl) == -1) 194 len = readline(response,256,ctl);
195 if (rsp) strcpy(rsp,response);
196 if (len == -1)
187 return 0; 197 return 0;
188 198
189 r = atoi(response)/100; 199 r = atoi(response)/100;
190 if(rsp) strcpy(rsp,response);
191 200
192 mp_msg(MSGT_STREAM,MSGL_V, "[ftp] < %s",response); 201 mp_msg(MSGT_STREAM,MSGL_V, "[ftp] < %s",response);
193 202
194 if (response[3] == '-') { 203 if (response[3] == '-') {
195 strncpy(match,response,3); 204 strncpy(match,response,3);