Patch/Bugfix for BOOTP in rtems-ss-20020205

Till Straumann strauman at SLAC.Stanford.EDU
Tue Mar 19 21:11:39 UTC 2002


Thomas Doerfler wrote:

> Hi Till,
>
> I got your ideas. I have finalized the patch
> (hopefully), find it attached to this mail.
>
> Joel, I also send this patch the the GNATS
> system...

Thomas

Hold on - unfortunately, the patch doesn't work
for me. The RTEMS/bsdnet headers seem to redefine
malloc() and free() to rtems_bsdnet_malloc() and
rtems_bsdnet_free(), respectively, which is probably
not what we want to call (since the memory was
allocated by strdup() using _real_ malloc().

Hence, I'd suggest to replace the call to free() in your
patch by a realloc() passing a size argument of zero.
This should be equivalent to a free().

Could you compile your version of the patch
without the compiler complaining about missing args???

Regards,

-- Till
-------------- next part --------------
*** bootp_subr.c.orig	Tue Mar 19 11:24:42 2002
--- bootp_subr.c	Tue Mar 19 13:06:53 2002
***************
*** 694,700 ****
  static char dhcp_gotlogserver = 0;
  static struct sockaddr_in dhcp_netmask;
  static struct sockaddr_in dhcp_gw;
! static char *dhcp_hostname;
  
  static void
  processOptions (unsigned char *optbuf, int optbufSize)
--- 694,700 ----
  static char dhcp_gotlogserver = 0;
  static struct sockaddr_in dhcp_netmask;
  static struct sockaddr_in dhcp_gw;
! static char *dhcp_hostname = NULL;
  
  static void
  processOptions (unsigned char *optbuf, int optbufSize)
***************
*** 801,806 ****
--- 801,815 ----
        if (sethostname (p, len) < 0)
          panic("Can't set host name");
        printf("Hostname is %s\n", p);
+       if (dhcp_hostname != NULL)
+        /* use realloc() instead of free() because RTEMS headers
+ 	    * redefine free to rtems_bsdnet_free() which needs extra args.
+         * This string was allocated by strdup() which does _not_
+         * call rtems_bsdnet_malloc() and hence we should release it
+ 	    * with 'real' free. Since realloc() has not been redefined
+ 	    * we might use it for this purpose.
+ 		*/
+        realloc(dhcp_hostname,0);
        dhcp_hostname = strdup(p);
        break;
  
***************
*** 904,911 ****
        update_files = 0;
      }
  
!   memset(dhcp_hostname, 0, sizeof(dhcp_hostname));
!   
    /*
     * Find a network interface.
     */
--- 913,923 ----
        update_files = 0;
      }
  
!   if (dhcp_hostname != NULL) {
! 	/* see comment above why we use realloc() */
!     dhcp_hostname=realloc(dhcp_hostname,0);
!   }
! 
    /*
     * Find a network interface.
     */


More information about the users mailing list