summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2021-03-22 16:28:25 +0000
committerflorian <florian@openbsd.org>2021-03-22 16:28:25 +0000
commit2d2edb0e3ca50fe71a66c867079a162d6456111e (patch)
tree8453ca944ed98b9c7e00b43482a426f19b5c0e95 /sbin
parentAvoid overflow by writing x = (y * 7) / 8 as x = y - (y / 8); ok florian (diff)
downloadwireguard-openbsd-2d2edb0e3ca50fe71a66c867079a162d6456111e.tar.xz
wireguard-openbsd-2d2edb0e3ca50fe71a66c867079a162d6456111e.zip
BOOTP has a minimum packet length of 300 bytes. Since DHCP is
interoperable with BOOTP we should also send packets that have a minimum size of 300. I haven't seen a DHCP server that actually enforces this except the one in vmd(8), but it doesn't cost us much and prevents hair pulling later on when we find one in the wild. OK deraadt
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dhcpleased/frontend.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sbin/dhcpleased/frontend.c b/sbin/dhcpleased/frontend.c
index 0c5d187e4c5..76313923dc8 100644
--- a/sbin/dhcpleased/frontend.c
+++ b/sbin/dhcpleased/frontend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: frontend.c,v 1.7 2021/03/19 07:43:27 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.8 2021/03/22 16:28:25 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@@ -57,6 +57,7 @@
#include "checksum.h"
#define ROUTE_SOCKET_BUF_SIZE 16384
+#define BOOTP_MIN_LEN 300 /* fixed bootp packet adds up to 300 */
struct bpf_ev {
struct event ev;
@@ -783,6 +784,7 @@ build_packet(uint8_t message_type, uint32_t xid, struct ether_addr *hw_address,
static uint8_t dhcp_server_identifier[] = {DHO_DHCP_SERVER_IDENTIFIER,
4, 0, 0, 0, 0};
struct dhcp_hdr *hdr;
+ ssize_t len;
uint8_t *p;
char *c;
@@ -834,7 +836,13 @@ build_packet(uint8_t message_type, uint32_t xid, struct ether_addr *hw_address,
*p = DHO_END;
p += 1;
- return (p - dhcp_packet);
+ len = p - dhcp_packet;
+
+ /* dhcp_packet is initialized with DHO_PADs */
+ if (len < BOOTP_MIN_LEN)
+ len = BOOTP_MIN_LEN;
+
+ return (len);
}
void