Browse Source

[pxe] Clarify comments regarding shrinking of cached DHCP packet

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
6de378aae8
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      src/arch/i386/core/cachedhcp.c

+ 9
- 6
src/arch/i386/core/cachedhcp.c View File

58
 	struct dhcp_packet *dhcppkt;
58
 	struct dhcp_packet *dhcppkt;
59
 	struct dhcp_packet *tmp;
59
 	struct dhcp_packet *tmp;
60
 	struct dhcphdr *dhcphdr;
60
 	struct dhcphdr *dhcphdr;
61
+	size_t max_len;
61
 	size_t len;
62
 	size_t len;
62
 
63
 
63
 	/* Do nothing if no cached DHCPACK is present */
64
 	/* Do nothing if no cached DHCPACK is present */
69
 	/* No reliable way to determine length before parsing packet;
70
 	/* No reliable way to determine length before parsing packet;
70
 	 * start by assuming maximum length permitted by PXE.
71
 	 * start by assuming maximum length permitted by PXE.
71
 	 */
72
 	 */
72
-	len = sizeof ( BOOTPLAYER_t );
73
+	max_len = sizeof ( BOOTPLAYER_t );
73
 
74
 
74
 	/* Allocate and populate DHCP packet */
75
 	/* Allocate and populate DHCP packet */
75
-	dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len );
76
+	dhcppkt = zalloc ( sizeof ( *dhcppkt ) + max_len );
76
 	if ( ! dhcppkt ) {
77
 	if ( ! dhcppkt ) {
77
 		DBGC ( colour, "CACHEDHCP could not allocate copy\n" );
78
 		DBGC ( colour, "CACHEDHCP could not allocate copy\n" );
78
 		return;
79
 		return;
79
 	}
80
 	}
80
 	dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) );
81
 	dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) );
81
 	copy_from_user ( dhcphdr, phys_to_user ( cached_dhcpack_phys ), 0,
82
 	copy_from_user ( dhcphdr, phys_to_user ( cached_dhcpack_phys ), 0,
82
-			 len );
83
-	dhcppkt_init ( dhcppkt, dhcphdr, len );
83
+			 max_len );
84
+	dhcppkt_init ( dhcppkt, dhcphdr, max_len );
84
 
85
 
85
-	/* Resize packet to required length.  If reallocation fails,
86
-	 * just continue to use the original packet.
86
+	/* Shrink packet to required length.  If reallocation fails,
87
+	 * just continue to use the original packet and waste the
88
+	 * unused space.
87
 	 */
89
 	 */
88
 	len = dhcppkt_len ( dhcppkt );
90
 	len = dhcppkt_len ( dhcppkt );
91
+	assert ( len <= max_len );
89
 	tmp = realloc ( dhcppkt, ( sizeof ( *dhcppkt ) + len ) );
92
 	tmp = realloc ( dhcppkt, ( sizeof ( *dhcppkt ) + len ) );
90
 	if ( tmp )
93
 	if ( tmp )
91
 		dhcppkt = tmp;
94
 		dhcppkt = tmp;

Loading…
Cancel
Save