Graham Gillies <[EMAIL PROTECTED]> writes:

> No doesn't seem to. I had a look at that and tried somthing similar
> and it didn't work. I then added a sockaddr_in in connect.c at about
> line 90 in 'if (opt.bind_address != NULL)' and zero'd it and tried
> to copy over the values from opt.bind_address and I'd get mem
> faults.

I think I understand what's going on: cmd_address() is seriously
flawed because it never allocates the memoty that opt.bind_address is
supposed to point to.  Instead, it effectively assigns the pointer a
stack-allocated value, which should not be touched as soon as
cmd_address exits!

If this option ever worked for anyone, it was through sheer luck.

Does this patch fix the problem?

Index: src/init.c
===================================================================
RCS file: /pack/anoncvs/wget/src/init.c,v
retrieving revision 1.23
diff -u -r1.23 init.c
--- src/init.c  2001/03/30 22:36:58     1.23
+++ src/init.c  2001/04/01 20:58:44
@@ -497,6 +497,7 @@
 cmd_address (const char *com, const char *val, void *closure)
 {
   struct sockaddr_in sin;
+  struct sockaddr_in **target = (struct sockaddr_in **)closure;
 
   if (!store_hostaddress ((unsigned char *)&sin.sin_addr, val))
     {
@@ -508,8 +509,11 @@
   sin.sin_family = AF_INET;
   sin.sin_port = 0;
 
-  memcpy (closure, &sin, sizeof (sin));
+  FREE_MAYBE (*target);
 
+  *target = xmalloc (sizeof (sin));
+  memcpy (*target, &sin, sizeof (sin));
+
   return 1;
 }
 

Reply via email to