diff options
author | Ron Yorston <rmy@pobox.com> | 2018-04-09 08:50:34 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-04-09 08:50:34 +0100 |
commit | 921c1ab66bad54d4ad8591bb74e41ac985248496 (patch) | |
tree | 552a04c691e78e78570e4ec2c83fbc0e59953924 /networking/wget.c | |
parent | 5b6f06f5eb8628955262508d153627fe6f2d1c8b (diff) | |
parent | a1870f4807a75663a085c9f5e92870fa7554f0ad (diff) | |
download | busybox-w32-921c1ab66bad54d4ad8591bb74e41ac985248496.tar.gz busybox-w32-921c1ab66bad54d4ad8591bb74e41ac985248496.tar.bz2 busybox-w32-921c1ab66bad54d4ad8591bb74e41ac985248496.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/networking/wget.c b/networking/wget.c index aaa068ba9..5ff31d278 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -794,12 +794,9 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags) | |||
794 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) | 794 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) |
795 | { | 795 | { |
796 | FILE *sfp; | 796 | FILE *sfp; |
797 | char *str; | 797 | char *pass; |
798 | int port; | 798 | int port; |
799 | 799 | ||
800 | if (!target->user) | ||
801 | target->user = xstrdup("anonymous:busybox@"); | ||
802 | |||
803 | sfp = open_socket(lsa); | 800 | sfp = open_socket(lsa); |
804 | #if ENABLE_FEATURE_WGET_HTTPS | 801 | #if ENABLE_FEATURE_WGET_HTTPS |
805 | if (target->protocol == P_FTPS) | 802 | if (target->protocol == P_FTPS) |
@@ -810,18 +807,20 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
810 | bb_error_msg_and_die("%s", G.wget_buf); | 807 | bb_error_msg_and_die("%s", G.wget_buf); |
811 | /* note: ftpcmd() sanitizes G.wget_buf, ok to print */ | 808 | /* note: ftpcmd() sanitizes G.wget_buf, ok to print */ |
812 | 809 | ||
813 | /* | 810 | /* Split username:password pair */ |
814 | * Splitting username:password pair, | 811 | pass = (char*)"busybox"; /* password for "anonymous" */ |
815 | * trying to log in | 812 | if (target->user) { |
816 | */ | 813 | pass = strchr(target->user, ':'); |
817 | str = strchr(target->user, ':'); | 814 | if (pass) |
818 | if (str) | 815 | *pass++ = '\0'; |
819 | *str++ = '\0'; | 816 | } |
820 | switch (ftpcmd("USER ", target->user, sfp)) { | 817 | |
818 | /* Log in */ | ||
819 | switch (ftpcmd("USER ", target->user ?: "anonymous", sfp)) { | ||
821 | case 230: | 820 | case 230: |
822 | break; | 821 | break; |
823 | case 331: | 822 | case 331: |
824 | if (ftpcmd("PASS ", str, sfp) == 230) | 823 | if (ftpcmd("PASS ", pass, sfp) == 230) |
825 | break; | 824 | break; |
826 | /* fall through (failed login) */ | 825 | /* fall through (failed login) */ |
827 | default: | 826 | default: |
@@ -830,20 +829,16 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
830 | 829 | ||
831 | ftpcmd("TYPE I", NULL, sfp); | 830 | ftpcmd("TYPE I", NULL, sfp); |
832 | 831 | ||
833 | /* | 832 | /* Query file size */ |
834 | * Querying file size | ||
835 | */ | ||
836 | if (ftpcmd("SIZE ", target->path, sfp) == 213) { | 833 | if (ftpcmd("SIZE ", target->path, sfp) == 213) { |
837 | G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10); | 834 | G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10); |
838 | if (G.content_len < 0 || errno) { | 835 | if (G.content_len < 0 || errno) { |
839 | bb_error_msg_and_die("SIZE value is garbage"); | 836 | bb_error_msg_and_die("bad SIZE value '%s'", G.wget_buf + 4); |
840 | } | 837 | } |
841 | G.got_clen = 1; | 838 | G.got_clen = 1; |
842 | } | 839 | } |
843 | 840 | ||
844 | /* | 841 | /* Enter passive mode */ |
845 | * Entering passive mode | ||
846 | */ | ||
847 | if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) { | 842 | if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) { |
848 | /* good */ | 843 | /* good */ |
849 | } else | 844 | } else |
@@ -1002,11 +997,19 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
1002 | if (!G.chunked) | 997 | if (!G.chunked) |
1003 | break; | 998 | break; |
1004 | 999 | ||
1005 | fgets_trim_sanitize(dfp, NULL); /* Eat empty line */ | 1000 | /* Each chunk ends with "\r\n" - eat it */ |
1001 | fgets_trim_sanitize(dfp, NULL); | ||
1006 | get_clen: | 1002 | get_clen: |
1003 | /* chunk size format is "HEXNUM[;name[=val]]\r\n" */ | ||
1007 | fgets_trim_sanitize(dfp, NULL); | 1004 | fgets_trim_sanitize(dfp, NULL); |
1005 | errno = 0; | ||
1008 | G.content_len = STRTOOFF(G.wget_buf, NULL, 16); | 1006 | G.content_len = STRTOOFF(G.wget_buf, NULL, 16); |
1009 | /* FIXME: error check? */ | 1007 | /* |
1008 | * Had a bug with inputs like "ffffffff0001f400" | ||
1009 | * smashing the heap later. Ensure >= 0. | ||
1010 | */ | ||
1011 | if (G.content_len < 0 || errno) | ||
1012 | bb_error_msg_and_die("bad chunk length '%s'", G.wget_buf); | ||
1010 | if (G.content_len == 0) | 1013 | if (G.content_len == 0) |
1011 | break; /* all done! */ | 1014 | break; /* all done! */ |
1012 | G.got_clen = 1; | 1015 | G.got_clen = 1; |