aboutsummaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-02-03 14:09:42 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-02-03 14:09:42 +0100
commitd353bfff467517608af7468198431d32406bb943 (patch)
treec10aca8d6ca2f3e39f3e8d474b0118d39491871c /networking/wget.c
parent69a12fa7906d2dcdb5d8e124643a4e0f7865417a (diff)
downloadbusybox-w32-d353bfff467517608af7468198431d32406bb943.tar.gz
busybox-w32-d353bfff467517608af7468198431d32406bb943.tar.bz2
busybox-w32-d353bfff467517608af7468198431d32406bb943.zip
wget: fix use-after-free of ->user. Closes 6836
function old new delta wget_main 2207 2223 +16 parse_url 339 353 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/wget.c')
-rw-r--r--networking/wget.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/networking/wget.c b/networking/wget.c
index d6c509edc..7ca947aec 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -46,7 +46,7 @@
46struct host_info { 46struct host_info {
47 char *allocated; 47 char *allocated;
48 const char *path; 48 const char *path;
49 const char *user; 49 char *user;
50 char *host; 50 char *host;
51 int port; 51 int port;
52 smallint is_ftp; 52 smallint is_ftp;
@@ -322,9 +322,6 @@ static void parse_url(const char *src_url, struct host_info *h)
322 h->path = sp; 322 h->path = sp;
323 } 323 }
324 324
325 // We used to set h->user to NULL here, but this interferes
326 // with handling of code 302 ("object was moved")
327
328 sp = strrchr(h->host, '@'); 325 sp = strrchr(h->host, '@');
329 if (sp != NULL) { 326 if (sp != NULL) {
330 // URL-decode "user:password" string before base64-encoding: 327 // URL-decode "user:password" string before base64-encoding:
@@ -333,11 +330,13 @@ static void parse_url(const char *src_url, struct host_info *h)
333 // which decodes to "test:my pass". 330 // which decodes to "test:my pass".
334 // Standard wget and curl do this too. 331 // Standard wget and curl do this too.
335 *sp = '\0'; 332 *sp = '\0';
336 h->user = percent_decode_in_place(h->host, /*strict:*/ 0); 333 free(h->user);
334 h->user = xstrdup(percent_decode_in_place(h->host, /*strict:*/ 0));
337 h->host = sp + 1; 335 h->host = sp + 1;
338 } 336 }
339 337 /* else: h->user remains NULL, or as set by original request
340 sp = h->host; 338 * before redirect (if we are here after a redirect).
339 */
341} 340}
342 341
343static char *gethdr(FILE *fp) 342static char *gethdr(FILE *fp)
@@ -880,6 +879,7 @@ However, in real world it was observed that some web servers
880 } else { 879 } else {
881 parse_url(str, &target); 880 parse_url(str, &target);
882 if (!use_proxy) { 881 if (!use_proxy) {
882 /* server.user remains untouched */
883 free(server.allocated); 883 free(server.allocated);
884 server.allocated = NULL; 884 server.allocated = NULL;
885 server.host = target.host; 885 server.host = target.host;
@@ -929,6 +929,8 @@ However, in real world it was observed that some web servers
929 929
930 free(server.allocated); 930 free(server.allocated);
931 free(target.allocated); 931 free(target.allocated);
932 free(server.user);
933 free(target.user);
932 free(fname_out_alloc); 934 free(fname_out_alloc);
933 free(redirected_path); 935 free(redirected_path);
934} 936}