summaryrefslogtreecommitdiffstats
path: root/src/arch/i386/core/cachedhcp.c
diff options
context:
space:
mode:
authorMichael Brown2016-02-11 20:14:00 +0100
committerMichael Brown2016-02-11 20:14:00 +0100
commit6de378aae80d614c6bd2ee69b09f1fa7facb3bd6 (patch)
treee5e4e6b12bc5de4b268277545e4018d9f9d2317f /src/arch/i386/core/cachedhcp.c
parent[iobuf] Improve robustness of I/O buffer allocation (diff)
downloadipxe-6de378aae80d614c6bd2ee69b09f1fa7facb3bd6.tar.gz
ipxe-6de378aae80d614c6bd2ee69b09f1fa7facb3bd6.tar.xz
ipxe-6de378aae80d614c6bd2ee69b09f1fa7facb3bd6.zip
[pxe] Clarify comments regarding shrinking of cached DHCP packet
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/i386/core/cachedhcp.c')
-rw-r--r--src/arch/i386/core/cachedhcp.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/arch/i386/core/cachedhcp.c b/src/arch/i386/core/cachedhcp.c
index a5c62403..ff35b925 100644
--- a/src/arch/i386/core/cachedhcp.c
+++ b/src/arch/i386/core/cachedhcp.c
@@ -58,6 +58,7 @@ static void cachedhcp_init ( void ) {
struct dhcp_packet *dhcppkt;
struct dhcp_packet *tmp;
struct dhcphdr *dhcphdr;
+ size_t max_len;
size_t len;
/* Do nothing if no cached DHCPACK is present */
@@ -69,23 +70,25 @@ static void cachedhcp_init ( void ) {
/* No reliable way to determine length before parsing packet;
* start by assuming maximum length permitted by PXE.
*/
- len = sizeof ( BOOTPLAYER_t );
+ max_len = sizeof ( BOOTPLAYER_t );
/* Allocate and populate DHCP packet */
- dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len );
+ dhcppkt = zalloc ( sizeof ( *dhcppkt ) + max_len );
if ( ! dhcppkt ) {
DBGC ( colour, "CACHEDHCP could not allocate copy\n" );
return;
}
dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) );
copy_from_user ( dhcphdr, phys_to_user ( cached_dhcpack_phys ), 0,
- len );
- dhcppkt_init ( dhcppkt, dhcphdr, len );
+ max_len );
+ dhcppkt_init ( dhcppkt, dhcphdr, max_len );
- /* Resize packet to required length. If reallocation fails,
- * just continue to use the original packet.
+ /* Shrink packet to required length. If reallocation fails,
+ * just continue to use the original packet and waste the
+ * unused space.
*/
len = dhcppkt_len ( dhcppkt );
+ assert ( len <= max_len );
tmp = realloc ( dhcppkt, ( sizeof ( *dhcppkt ) + len ) );
if ( tmp )
dhcppkt = tmp;