Browse code

lavf/ftp: always treat all response codes >= 500 as error

Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>

Lukasz Marek authored on 2014/07/04 08:05:48
Showing 1 changed files
... ...
@@ -149,13 +149,17 @@ static int ftp_status(FTPContext *s, char **line, const int response_codes[])
149 149
         }
150 150
 
151 151
         if (!code_found) {
152
-            for (i = 0; response_codes[i]; ++i) {
153
-                if (err == response_codes[i]) {
154
-                    code_found = 1;
155
-                    result = err;
156
-                    break;
152
+            if (err >= 500) {
153
+                code_found = 1;
154
+                result = err;
155
+            } else
156
+                for (i = 0; response_codes[i]; ++i) {
157
+                    if (err == response_codes[i]) {
158
+                        code_found = 1;
159
+                        result = err;
160
+                        break;
161
+                    }
157 162
                 }
158
-            }
159 163
         }
160 164
         if (code_found) {
161 165
             if (line)
... ...
@@ -209,8 +213,8 @@ static int ftp_auth(FTPContext *s)
209 209
     const char *user = NULL, *pass = NULL;
210 210
     char *end = NULL, buf[CONTROL_BUFFER_SIZE], credencials[CREDENTIALS_BUFFER_SIZE];
211 211
     int err;
212
-    static const int user_codes[] = {331, 230, 500, 530, 0}; /* 500, 530 are incorrect codes */
213
-    static const int pass_codes[] = {230, 503, 530, 0}; /* 503, 530 are incorrect codes */
212
+    static const int user_codes[] = {331, 230, 0};
213
+    static const int pass_codes[] = {230, 0};
214 214
 
215 215
     /* Authentication may be repeated, original string has to be saved */
216 216
     av_strlcpy(credencials, s->credencials, sizeof(credencials));
... ...
@@ -244,7 +248,7 @@ static int ftp_passive_mode_epsv(FTPContext *s)
244 244
     int i;
245 245
     static const char d = '|';
246 246
     static const char *command = "EPSV\r\n";
247
-    static const int epsv_codes[] = {229, 500, 501, 0}; /* 500, 501 are incorrect codes */
247
+    static const int epsv_codes[] = {229, 0};
248 248
 
249 249
     if (ftp_send_command(s, command, epsv_codes, &res) != 229 || !res)
250 250
         goto fail;
... ...
@@ -285,7 +289,7 @@ static int ftp_passive_mode(FTPContext *s)
285 285
     char *res = NULL, *start = NULL, *end = NULL;
286 286
     int i;
287 287
     static const char *command = "PASV\r\n";
288
-    static const int pasv_codes[] = {227, 501, 0}; /* 501 is incorrect code */
288
+    static const int pasv_codes[] = {227, 0};
289 289
 
290 290
     if (ftp_send_command(s, command, pasv_codes, &res) != 227 || !res)
291 291
         goto fail;
... ...
@@ -368,7 +372,7 @@ static int ftp_file_size(FTPContext *s)
368 368
 {
369 369
     char command[CONTROL_BUFFER_SIZE];
370 370
     char *res = NULL;
371
-    static const int size_codes[] = {213, 501, 550, 0}; /* 501, 550 are incorrect codes */
371
+    static const int size_codes[] = {213, 0};
372 372
 
373 373
     snprintf(command, sizeof(command), "SIZE %s\r\n", s->path);
374 374
     if (ftp_send_command(s, command, size_codes, &res) == 213 && res) {
... ...
@@ -386,7 +390,7 @@ static int ftp_file_size(FTPContext *s)
386 386
 static int ftp_retrieve(FTPContext *s)
387 387
 {
388 388
     char command[CONTROL_BUFFER_SIZE];
389
-    static const int retr_codes[] = {150, 550, 554, 0}; /* 550, 554 are incorrect codes */
389
+    static const int retr_codes[] = {150, 0};
390 390
 
391 391
     snprintf(command, sizeof(command), "RETR %s\r\n", s->path);
392 392
     if (ftp_send_command(s, command, retr_codes, NULL) != 150)
... ...
@@ -414,7 +418,7 @@ static int ftp_store(FTPContext *s)
414 414
 static int ftp_type(FTPContext *s)
415 415
 {
416 416
     static const char *command = "TYPE I\r\n";
417
-    static const int type_codes[] = {200, 500, 504, 0}; /* 500, 504 are incorrect codes */
417
+    static const int type_codes[] = {200, 0};
418 418
 
419 419
     if (ftp_send_command(s, command, type_codes, NULL) != 200)
420 420
         return AVERROR(EIO);
... ...
@@ -425,7 +429,7 @@ static int ftp_type(FTPContext *s)
425 425
 static int ftp_restart(FTPContext *s, int64_t pos)
426 426
 {
427 427
     char command[CONTROL_BUFFER_SIZE];
428
-    static const int rest_codes[] = {350, 500, 501, 0}; /* 500, 501 are incorrect codes */
428
+    static const int rest_codes[] = {350, 0};
429 429
 
430 430
     snprintf(command, sizeof(command), "REST %"PRId64"\r\n", pos);
431 431
     if (ftp_send_command(s, command, rest_codes, NULL) != 350)
... ...
@@ -438,8 +442,8 @@ static int ftp_features(FTPContext *s)
438 438
 {
439 439
     static const char *feat_command        = "FEAT\r\n";
440 440
     static const char *enable_utf8_command = "OPTS UTF8 ON\r\n";
441
-    static const int feat_codes[] = {211, 500, 502, 0};   /* 500, 502 are incorrect codes */
442
-    static const int opts_codes[] = {200, 451, 500, 502}; /* 500, 451, 502 are incorrect codes */
441
+    static const int feat_codes[] = {211, 0};
442
+    static const int opts_codes[] = {200, 451};
443 443
     char *feat;
444 444
 
445 445
     if (ftp_send_command(s, feat_command, feat_codes, &feat) == 211) {