aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/common.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-17 18:07:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-17 18:07:18 +0100
commit6d3b4bb24da9a07c263f3c1acf8df85382ff562c (patch)
tree62b1094f93c955774e8b2d4aee798029a5a71b7d /networking/udhcp/common.c
parent4b72aebe80aaa50a765d5ff61d7d67ed731502d9 (diff)
downloadbusybox-6d3b4bb24da9a07c263f3c1acf8df85382ff562c.tar.gz
udhcpc: check that 4-byte options are indeed 4-byte, closes 11506
function old new delta udhcp_get_option32 - 27 +27 udhcp_get_option 231 248 +17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 44/0) Total: 44 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r--networking/udhcp/common.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index e5fd74f91..41b05b855 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -272,6 +272,15 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
goto complain; /* complain and return NULL */
if (optionptr[OPT_CODE] == code) {
+ if (optionptr[OPT_LEN] == 0) {
+ /* So far no valid option with length 0 known.
+ * Having this check means that searching
+ * for DHCP_MESSAGE_TYPE need not worry
+ * that returned pointer might be unsafe
+ * to dereference.
+ */
+ goto complain; /* complain and return NULL */
+ }
log_option("option found", optionptr);
return optionptr + OPT_DATA;
}
@@ -289,6 +298,16 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
return NULL;
}
+uint8_t* FAST_FUNC udhcp_get_option32(struct dhcp_packet *packet, int code)
+{
+ uint8_t *r = udhcp_get_option(packet, code);
+ if (r) {
+ if (r[-1] != 4)
+ r = NULL;
+ }
+ return r;
+}
+
/* Return the position of the 'end' option (no bounds checking) */
int FAST_FUNC udhcp_end_option(uint8_t *optionptr)
{