]> sjero.net Git - wget/commitdiff
[svn] Fix memory allocation in cmd_address().
authorhniksic <devnull@localhost>
Sun, 1 Apr 2001 22:23:52 +0000 (15:23 -0700)
committerhniksic <devnull@localhost>
Sun, 1 Apr 2001 22:23:52 +0000 (15:23 -0700)
Published in <sxs66gogt0k.fsf@florida.arsdigita.de> under
the subject "Fix for opt.bind_address".

src/ChangeLog
src/init.c

index f3c7f7007d73191de7e11e97ccee2b7e9f8d446c..d7d60c6993990429b9011bcda444bcbaa1c58b1e 100644 (file)
@@ -1,3 +1,8 @@
+2001-04-02  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * init.c (cmd_address): Heap-allocate the address that gets stored
+       to CLOSURE.  Old code would simply assign an address on the stack.
+
 2001-04-01  Nicolas Lichtmaier <nick@debian.org>
 
        * ftp.c (ftp_get_listing): Propagate error status.
index ffda428ad15244a3ec8cc24cf95b37235fb1546c..cae3681a675e3be7a8c152d07786ae118d34ac11 100644 (file)
@@ -491,12 +491,21 @@ setval (const char *com, const char *val)
 
 static int myatoi PARAMS ((const char *s));
 
-/* Store the address (specified as hostname or dotted-quad IP address) from VAL
-   to CLOSURE.  COM is ignored, except for error messages.  */
+/* Interpret VAL as an Internet address (a hostname or a dotted-quad
+   IP address), and write it (in network order) to a malloc-allocated
+   address.  That address gets stored to the memory pointed to by
+   CLOSURE.  COM is ignored, except for error messages.
+
+   #### IMHO it's a mistake to do this kind of work so early in the
+   process (before any download even started!)  opt.bind_address
+   should simply remember the provided value as a string.  Another
+   function should do the lookup, when needed, and cache the
+   result.  --hniksic  */
 static int
 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,7 +517,10 @@ cmd_address (const char *com, const char *val, void *closure)
   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;
 }
@@ -1021,4 +1033,5 @@ cleanup (void)
   FREE_MAYBE (opt.sslcertkey);
   FREE_MAYBE (opt.sslcertfile);
 #endif /* HAVE_SSL */
+  FREE_MAYBE (opt.bind_address);
 }