diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-15 17:05:55 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-15 17:05:55 +0000 |
| commit | 023b57d935dedda30e577e8be1461eec27294c93 (patch) | |
| tree | 18e302d512c7e210181b57734c261708ec50c9fa | |
| parent | efeed5ed28a04e1353f063daa60ca04b37f681ec (diff) | |
| download | busybox-w32-023b57d935dedda30e577e8be1461eec27294c93.tar.gz busybox-w32-023b57d935dedda30e577e8be1461eec27294c93.tar.bz2 busybox-w32-023b57d935dedda30e577e8be1461eec27294c93.zip | |
wget: xatoi's were oversealous ("200 OK" isn't a number)
| -rw-r--r-- | networking/wget.c | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/networking/wget.c b/networking/wget.c index 7a931f363..1b132bea8 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -290,33 +290,36 @@ int wget_main(int argc, char **argv) | |||
| 290 | /* | 290 | /* |
| 291 | * Retrieve HTTP response line and check for "200" status code. | 291 | * Retrieve HTTP response line and check for "200" status code. |
| 292 | */ | 292 | */ |
| 293 | read_response: | 293 | read_response: |
| 294 | if (fgets(buf, sizeof(buf), sfp) == NULL) | 294 | if (fgets(buf, sizeof(buf), sfp) == NULL) |
| 295 | bb_error_msg_and_die("no response from server"); | 295 | bb_error_msg_and_die("no response from server"); |
| 296 | 296 | ||
| 297 | s = buf; | 297 | s = buf; |
| 298 | while (*s != '\0' && !isspace(*s)) ++s; | 298 | while (*s != '\0' && !isspace(*s)) ++s; |
| 299 | while (isspace(*s)) ++s; | 299 | while (isspace(*s)) ++s; |
| 300 | switch (status = xatoi(s)) { | 300 | // FIXME: no error check |
| 301 | case 0: | 301 | // xatou wouldn't work: "200 OK" |
| 302 | case 100: | 302 | status = atoi(s); |
| 303 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) | 303 | switch (status) { |
| 304 | /* eat all remaining headers */; | 304 | case 0: |
| 305 | goto read_response; | 305 | case 100: |
| 306 | case 200: | 306 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) |
| 307 | break; | 307 | /* eat all remaining headers */; |
| 308 | case 300: /* redirection */ | 308 | goto read_response; |
| 309 | case 301: | 309 | case 200: |
| 310 | case 302: | 310 | break; |
| 311 | case 303: | 311 | case 300: /* redirection */ |
| 312 | case 301: | ||
| 313 | case 302: | ||
| 314 | case 303: | ||
| 315 | break; | ||
| 316 | case 206: | ||
| 317 | if (beg_range) | ||
| 312 | break; | 318 | break; |
| 313 | case 206: | 319 | /*FALLTHRU*/ |
| 314 | if (beg_range) | 320 | default: |
| 315 | break; | 321 | chomp(buf); |
| 316 | /*FALLTHRU*/ | 322 | bb_error_msg_and_die("server returned error %s: %s", s, buf); |
| 317 | default: | ||
| 318 | chomp(buf); | ||
| 319 | bb_error_msg_and_die("server returned error %s: %s", s, buf); | ||
| 320 | } | 323 | } |
| 321 | 324 | ||
| 322 | /* | 325 | /* |
| @@ -331,11 +334,9 @@ read_response: | |||
| 331 | continue; | 334 | continue; |
| 332 | } | 335 | } |
| 333 | if (strcasecmp(buf, "transfer-encoding") == 0) { | 336 | if (strcasecmp(buf, "transfer-encoding") == 0) { |
| 334 | if (strcasecmp(s, "chunked") == 0) { | 337 | if (strcasecmp(s, "chunked") != 0) |
| 335 | chunked = got_clen = 1; | ||
| 336 | } else { | ||
| 337 | bb_error_msg_and_die("server wants to do %s transfer encoding", s); | 338 | bb_error_msg_and_die("server wants to do %s transfer encoding", s); |
| 338 | } | 339 | chunked = got_clen = 1; |
| 339 | } | 340 | } |
| 340 | if (strcasecmp(buf, "location") == 0) { | 341 | if (strcasecmp(buf, "location") == 0) { |
| 341 | if (s[0] == '/') | 342 | if (s[0] == '/') |
| @@ -377,14 +378,14 @@ read_response: | |||
| 377 | if (s) | 378 | if (s) |
| 378 | *(s++) = '\0'; | 379 | *(s++) = '\0'; |
| 379 | switch (ftpcmd("USER ", target.user, sfp, buf)) { | 380 | switch (ftpcmd("USER ", target.user, sfp, buf)) { |
| 380 | case 230: | 381 | case 230: |
| 382 | break; | ||
| 383 | case 331: | ||
| 384 | if (ftpcmd("PASS ", s, sfp, buf) == 230) | ||
| 381 | break; | 385 | break; |
| 382 | case 331: | 386 | /* FALLTHRU (failed login) */ |
| 383 | if (ftpcmd("PASS ", s, sfp, buf) == 230) | 387 | default: |
| 384 | break; | 388 | bb_error_msg_and_die("ftp login: %s", buf+4); |
| 385 | /* FALLTHRU (failed login) */ | ||
| 386 | default: | ||
| 387 | bb_error_msg_and_die("ftp login: %s", buf+4); | ||
| 388 | } | 389 | } |
| 389 | 390 | ||
| 390 | ftpcmd("TYPE I", NULL, sfp, buf); | 391 | ftpcmd("TYPE I", NULL, sfp, buf); |
| @@ -402,12 +403,19 @@ read_response: | |||
| 402 | /* | 403 | /* |
| 403 | * Entering passive mode | 404 | * Entering passive mode |
| 404 | */ | 405 | */ |
| 405 | if (ftpcmd("PASV", NULL, sfp, buf) != 227) | 406 | if (ftpcmd("PASV", NULL, sfp, buf) != 227) { |
| 406 | bb_error_msg_and_die("PASV: %s", buf+4); | 407 | pasv_error: |
| 408 | bb_error_msg_and_die("bad response to %s: %s", "PASV", buf); | ||
| 409 | } | ||
| 410 | // Response is "227 garbageN1,N2,N3,N4,P1,P2 | ||
| 411 | // Server's IP is N1.N2.N3.N4 (we ignore it) | ||
| 412 | // Server's port for data connection is P1*256+P2 | ||
| 407 | s = strrchr(buf, ','); | 413 | s = strrchr(buf, ','); |
| 408 | *s = 0; | 414 | if (!s) goto pasv_error; |
| 409 | port = xatol_range(s+1, 0, 255); | 415 | port = xatol_range(s+1, 0, 255); |
| 416 | *s = '\0'; | ||
| 410 | s = strrchr(buf, ','); | 417 | s = strrchr(buf, ','); |
| 418 | if (!s) goto pasv_error; | ||
| 411 | port += xatol_range(s+1, 0, 255) * 256; | 419 | port += xatol_range(s+1, 0, 255) * 256; |
| 412 | s_in.sin_port = htons(port); | 420 | s_in.sin_port = htons(port); |
| 413 | dfp = open_socket(&s_in); | 421 | dfp = open_socket(&s_in); |
| @@ -419,7 +427,7 @@ read_response: | |||
| 419 | } | 427 | } |
| 420 | 428 | ||
| 421 | if (ftpcmd("RETR ", target.path, sfp, buf) > 150) | 429 | if (ftpcmd("RETR ", target.path, sfp, buf) > 150) |
| 422 | bb_error_msg_and_die("RETR: %s", buf+4); | 430 | bb_error_msg_and_die("bad response to %s: %s", "RETR", buf); |
| 423 | } | 431 | } |
| 424 | 432 | ||
| 425 | 433 | ||
| @@ -510,7 +518,7 @@ static void parse_url(char *src_url, struct host_info *h) | |||
| 510 | // and saves 'index.html?var=a%2Fb' (we save 'b') | 518 | // and saves 'index.html?var=a%2Fb' (we save 'b') |
| 511 | // wget 'http://busybox.net?login=john@doe': | 519 | // wget 'http://busybox.net?login=john@doe': |
| 512 | // request: 'GET /?login=john@doe HTTP/1.0' | 520 | // request: 'GET /?login=john@doe HTTP/1.0' |
| 513 | // saves: 'index.html?login=john@doe' (we save ?login=john@doe) | 521 | // saves: 'index.html?login=john@doe' (we save '?login=john@doe') |
| 514 | // wget 'http://busybox.net#test/test': | 522 | // wget 'http://busybox.net#test/test': |
| 515 | // request: 'GET / HTTP/1.0' | 523 | // request: 'GET / HTTP/1.0' |
| 516 | // saves: 'index.html' (we save 'test') | 524 | // saves: 'index.html' (we save 'test') |
| @@ -628,8 +636,9 @@ static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc) | |||
| 628 | 636 | ||
| 629 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | 637 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) |
| 630 | { | 638 | { |
| 639 | int result; | ||
| 631 | if (s1) { | 640 | if (s1) { |
| 632 | if (!s2) s2=""; | 641 | if (!s2) s2 = ""; |
| 633 | fprintf(fp, "%s%s\r\n", s1, s2); | 642 | fprintf(fp, "%s%s\r\n", s1, s2); |
| 634 | fflush(fp); | 643 | fflush(fp); |
| 635 | } | 644 | } |
| @@ -638,7 +647,7 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | |||
| 638 | char *buf_ptr; | 647 | char *buf_ptr; |
| 639 | 648 | ||
| 640 | if (fgets(buf, 510, fp) == NULL) { | 649 | if (fgets(buf, 510, fp) == NULL) { |
| 641 | bb_perror_msg_and_die("fgets"); | 650 | bb_perror_msg_and_die("error getting response"); |
| 642 | } | 651 | } |
| 643 | buf_ptr = strstr(buf, "\r\n"); | 652 | buf_ptr = strstr(buf, "\r\n"); |
| 644 | if (buf_ptr) { | 653 | if (buf_ptr) { |
| @@ -646,7 +655,10 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | |||
| 646 | } | 655 | } |
| 647 | } while (!isdigit(buf[0]) || buf[3] != ' '); | 656 | } while (!isdigit(buf[0]) || buf[3] != ' '); |
| 648 | 657 | ||
| 649 | return xatoi(buf); | 658 | buf[3] = '\0'; |
| 659 | result = xatoi_u(buf); | ||
| 660 | buf[3] = ' '; | ||
| 661 | return result; | ||
| 650 | } | 662 | } |
| 651 | 663 | ||
| 652 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 664 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
