From: Tobias Brunner Date: Tue, 10 Apr 2018 16:19:35 +0000 (+0200) Subject: dhcp: Increase buffer size for options in DHCP messages X-Git-Tag: 5.6.3dr2~6^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=30e886fe3bb6ecb38a58370de447ec735ff9cc51;p=thirdparty%2Fstrongswan.git dhcp: Increase buffer size for options in DHCP messages According to RFC 2131, the minimum size of the 'options' field is 312 bytes, including the 4 byte magic cookie. There also does not seem to be any restriction regarding the message length, previously the length was rounded to a multiple of 64 bytes. The latter might have been because in BOOTP the options field (or rather vendor-specific area as it was called back then) had a fixed length of 64 bytes (so max(optlen+4, 64) might actually have been what was intended), but for DHCP the field is explicitly variable length, so I don't think it's necessary to pad it. --- diff --git a/src/libcharon/plugins/dhcp/dhcp_socket.c b/src/libcharon/plugins/dhcp/dhcp_socket.c index 3167b0503b..7b64380b7a 100644 --- a/src/libcharon/plugins/dhcp/dhcp_socket.c +++ b/src/libcharon/plugins/dhcp/dhcp_socket.c @@ -160,7 +160,7 @@ typedef struct __attribute__((packed)) { } dhcp_option_t; /** - * DHCP message format, with a maximum size options buffer + * DHCP message format, with a minimum size options buffer */ typedef struct __attribute__((packed)) { uint8_t opcode; @@ -179,7 +179,7 @@ typedef struct __attribute__((packed)) { char server_hostname[64]; char boot_filename[128]; uint32_t magic_cookie; - u_char options[252]; + u_char options[308]; } dhcp_t; /** @@ -286,7 +286,7 @@ static bool send_dhcp(private_dhcp_socket_t *this, { dst = this->dst; } - len = offsetof(dhcp_t, magic_cookie) + ((optlen + 4) / 64 * 64 + 64); + len = offsetof(dhcp_t, magic_cookie) + optlen + 4; return sendto(this->send, dhcp, len, 0, dst->get_sockaddr(dst), *dst->get_sockaddr_len(dst)) == len; }