]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Check the magic cookie when retreiving an option.
authorRoy Marples <roy@marples.name>
Sun, 5 Apr 2015 16:28:54 +0000 (16:28 +0000)
committerRoy Marples <roy@marples.name>
Sun, 5 Apr 2015 16:28:54 +0000 (16:28 +0000)
dhcp.c
dhcp.h

diff --git a/dhcp.c b/dhcp.c
index a72dc79d59c714784b85c7690f1f58b6cc7d3861..8b10287add6af0f711d38353c357735caf800b40 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -160,6 +160,12 @@ get_option(struct dhcpcd_ctx *ctx,
        const uint8_t *op = NULL;
        size_t bl = 0;
 
+       /* Check we have the magic cookie */
+       if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
+               errno = ENOTSUP;
+               return NULL;
+       }
+
        while (p < e) {
                o = *p++;
                if (o == opt) {
@@ -1059,7 +1065,7 @@ write_lease(const struct interface *ifp, const struct dhcp_message *dhcp)
        const struct dhcp_state *state = D_CSTATE(ifp);
 
        /* We don't write BOOTP leases */
-       if (is_bootp(ifp, dhcp)) {
+       if (IS_BOOTP(ifp, dhcp)) {
                unlink(state->leasefile);
                return 0;
        }
@@ -1126,7 +1132,8 @@ read_lease(struct interface *ifp)
 
        /* We may have found a BOOTP server */
        if (get_option_uint8(ifp->ctx, &type, dhcp, DHO_MESSAGETYPE) == -1)
-               type = 0;
+               return dhcp;
+
        /* Authenticate the message */
        auth = get_option(ifp->ctx, dhcp, DHO_AUTHENTICATION, &auth_len);
        if (auth) {
@@ -1619,7 +1626,7 @@ send_message(struct interface *ifp, uint8_t type,
         * Also, we should not unicast from a BOOTP lease. */
        if (s == -1 ||
            (!(ifo->options & DHCPCD_INFORM) &&
-           is_bootp(ifp, state->new)))
+           IS_BOOTP(ifp, state->new)))
        {
                a = state->addr.s_addr;
                state->addr.s_addr = INADDR_ANY;
@@ -2554,9 +2561,9 @@ dhcp_handledhcp(struct interface *ifp, struct dhcp_message **dhcpp,
                if (has_option_mask(ifo->requiremask, i) &&
                    get_option_uint8(ifp->ctx, &tmp, dhcp, (uint8_t)i) != 0)
                {
-                       /* If we are bootp, then ignore the need for serverid.
-                        * To ignore bootp, require dhcp_message_type.
-                        * However, nothing really stops bootp from providing
+                       /* If we are BOOTP, then ignore the need for serverid.
+                        * To ignore BOOTP, require dhcp_message_type.
+                        * However, nothing really stops BOOTP from providing
                         * DHCP style options as well so the above isn't
                         * always true. */
                        if (type == 0 && i == DHO_SERVERID)
diff --git a/dhcp.h b/dhcp.h
index 6fd8229ddaac0cbc5b037c879832623359a51efd..05ff69f11971e8a0777a715a755fa25b7d9ecf44 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -257,8 +257,8 @@ void dhcp_printoptions(const struct dhcpcd_ctx *,
     const struct dhcp_opt *, size_t);
 int get_option_addr(struct dhcpcd_ctx *,struct in_addr *,
     const struct dhcp_message *, uint8_t);
-#define is_bootp(i, m) ((m) &&                                         \
-           !IN_LINKLOCAL(htonl((m)->yiaddr)) &&                        \
+#define IS_BOOTP(i, m) ((m) &&                                             \
+           !IN_LINKLOCAL(htonl((m)->yiaddr)) &&                            \
            get_option_uint8((i)->ctx, NULL, (m), DHO_MESSAGETYPE) == -1)
 struct rt_head *get_option_routes(struct interface *,
     const struct dhcp_message *);