diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-07 14:28:55 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-07 14:28:55 +0000 |
commit | 96e9d3c968b252c0dac5b497c003e961bd408570 (patch) | |
tree | 19a894496a6ad840f1b1055c3f62dac5af236d60 /networking/wget.c | |
parent | a655152b0045a9ac39718dcbf60b314f32c43413 (diff) | |
download | busybox-w32-96e9d3c968b252c0dac5b497c003e961bd408570.tar.gz busybox-w32-96e9d3c968b252c0dac5b497c003e961bd408570.tar.bz2 busybox-w32-96e9d3c968b252c0dac5b497c003e961bd408570.zip |
wget: don't be careless with xstrdup'ing
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/networking/wget.c b/networking/wget.c index 3f36e4861..788c291b9 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | struct host_info { | 32 | struct host_info { |
33 | // May be used if we ever will want to free() all xstrdup()s... | ||
34 | /* char *allocated; */ | ||
33 | char *host; | 35 | char *host; |
34 | int port; | 36 | int port; |
35 | char *path; | 37 | char *path; |
@@ -136,14 +138,16 @@ int wget_main(int argc, char **argv) | |||
136 | struct sockaddr_in s_in; | 138 | struct sockaddr_in s_in; |
137 | llist_t *headers_llist = NULL; | 139 | llist_t *headers_llist = NULL; |
138 | 140 | ||
141 | /* server.allocated = target.allocated = NULL; */ | ||
142 | |||
139 | FILE *sfp = NULL; /* socket to web/ftp server */ | 143 | FILE *sfp = NULL; /* socket to web/ftp server */ |
140 | FILE *dfp = NULL; /* socket to ftp server (data) */ | 144 | FILE *dfp = NULL; /* socket to ftp server (data) */ |
141 | char *fname_out = NULL; /* where to direct output (-O) */ | 145 | char *fname_out = NULL; /* where to direct output (-O) */ |
142 | int got_clen = 0; /* got content-length: from server */ | 146 | int got_clen = 0; /* got content-length: from server */ |
143 | int output_fd = -1; | 147 | int output_fd = -1; |
144 | int use_proxy = 1; /* Use proxies if env vars are set */ | 148 | int use_proxy = 1; /* Use proxies if env vars are set */ |
145 | char *proxy_flag = "on"; /* Use proxies if env vars are set */ | 149 | const char *proxy_flag = "on"; /* Use proxies if env vars are set */ |
146 | char *user_agent = "Wget"; /* Content of the "User-Agent" header field */ | 150 | const char *user_agent = "Wget";/* Content of the "User-Agent" header field */ |
147 | 151 | ||
148 | /* | 152 | /* |
149 | * Crack command line. | 153 | * Crack command line. |
@@ -185,7 +189,7 @@ int wget_main(int argc, char **argv) | |||
185 | if (use_proxy) { | 189 | if (use_proxy) { |
186 | proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); | 190 | proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); |
187 | if (proxy && *proxy) { | 191 | if (proxy && *proxy) { |
188 | parse_url(xstrdup(proxy), &server); | 192 | parse_url(proxy, &server); |
189 | } else { | 193 | } else { |
190 | use_proxy = 0; | 194 | use_proxy = 0; |
191 | } | 195 | } |
@@ -306,14 +310,14 @@ read_response: | |||
306 | if (fgets(buf, sizeof(buf), sfp) == NULL) | 310 | if (fgets(buf, sizeof(buf), sfp) == NULL) |
307 | bb_error_msg_and_die("no response from server"); | 311 | bb_error_msg_and_die("no response from server"); |
308 | 312 | ||
309 | for (s = buf ; *s != '\0' && !isspace(*s) ; ++s) | 313 | s = buf; |
310 | ; | 314 | while (*s != '\0' && !isspace(*s)) ++s; |
311 | for ( ; isspace(*s) ; ++s) | 315 | while (isspace(*s)) ++s; |
312 | ; | ||
313 | switch (status = atoi(s)) { | 316 | switch (status = atoi(s)) { |
314 | case 0: | 317 | case 0: |
315 | case 100: | 318 | case 100: |
316 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL); | 319 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) |
320 | /* eat all remaining headers */; | ||
317 | goto read_response; | 321 | goto read_response; |
318 | case 200: | 322 | case 200: |
319 | break; | 323 | break; |
@@ -328,7 +332,7 @@ read_response: | |||
328 | /*FALLTHRU*/ | 332 | /*FALLTHRU*/ |
329 | default: | 333 | default: |
330 | chomp(buf); | 334 | chomp(buf); |
331 | bb_error_msg_and_die("server returned error %d: %s", atoi(s), buf); | 335 | bb_error_msg_and_die("server returned error %s: %s", s, buf); |
332 | } | 336 | } |
333 | 337 | ||
334 | /* | 338 | /* |
@@ -351,10 +355,10 @@ read_response: | |||
351 | } | 355 | } |
352 | if (strcasecmp(buf, "location") == 0) { | 356 | if (strcasecmp(buf, "location") == 0) { |
353 | if (s[0] == '/') | 357 | if (s[0] == '/') |
354 | // FIXME: this is dirty | 358 | /* free(target.allocated); */ |
355 | target.path = xstrdup(s+1); | 359 | target.path = /* target.allocated = */ xstrdup(s+1); |
356 | else { | 360 | else { |
357 | parse_url(xstrdup(s), &target); | 361 | parse_url(s, &target); |
358 | if (use_proxy == 0) { | 362 | if (use_proxy == 0) { |
359 | server.host = target.host; | 363 | server.host = target.host; |
360 | server.port = target.port; | 364 | server.port = target.port; |
@@ -368,9 +372,9 @@ read_response: | |||
368 | } while(status >= 300); | 372 | } while(status >= 300); |
369 | 373 | ||
370 | dfp = sfp; | 374 | dfp = sfp; |
371 | } | 375 | |
372 | else | 376 | } else { |
373 | { | 377 | |
374 | /* | 378 | /* |
375 | * FTP session | 379 | * FTP session |
376 | */ | 380 | */ |
@@ -499,9 +503,11 @@ read_response: | |||
499 | } | 503 | } |
500 | 504 | ||
501 | 505 | ||
502 | static void parse_url(char *url, struct host_info *h) | 506 | static void parse_url(char *src_url, struct host_info *h) |
503 | { | 507 | { |
504 | char *p, *cp, *sp, *up, *pp; | 508 | char *url, *p, *cp, *sp, *up, *pp; |
509 | |||
510 | /* h->allocated = */ url = xstrdup(src_url); | ||
505 | 511 | ||
506 | if (strncmp(url, "http://", 7) == 0) { | 512 | if (strncmp(url, "http://", 7) == 0) { |
507 | h->port = bb_lookup_port("http", "tcp", 80); | 513 | h->port = bb_lookup_port("http", "tcp", 80); |
@@ -517,7 +523,7 @@ static void parse_url(char *url, struct host_info *h) | |||
517 | // FYI: | 523 | // FYI: |
518 | // "Real" wget 'http://busybox.net?var=a/b' sends this request: | 524 | // "Real" wget 'http://busybox.net?var=a/b' sends this request: |
519 | // 'GET /?var=a/b HTTP 1.0' | 525 | // 'GET /?var=a/b HTTP 1.0' |
520 | // and saves 'index.html?var=a%2Fb' | 526 | // and saves 'index.html?var=a%2Fb' (we save 'b') |
521 | // wget 'http://busybox.net?login=john@doe': | 527 | // wget 'http://busybox.net?login=john@doe': |
522 | // request: 'GET /?login=john@doe HTTP/1.0' | 528 | // request: 'GET /?login=john@doe HTTP/1.0' |
523 | // saves: 'index.html?login=john@doe' (we save ?login=john@doe) | 529 | // saves: 'index.html?login=john@doe' (we save ?login=john@doe) |