]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If we have space, ensure our packet options are correctly terminated.
authorRoy Marples <roy@marples.name>
Wed, 14 May 2008 09:07:54 +0000 (09:07 +0000)
committerRoy Marples <roy@marples.name>
Wed, 14 May 2008 09:07:54 +0000 (09:07 +0000)
client.c

index af0d8169b7ac0f102a5002adc03865052e19452b..1227c6b89f15efb1dfbf25acf891e8e2289baf1b 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1185,6 +1185,8 @@ handle_packet(struct if_state *state, const struct options *options)
 {
        struct interface *iface = state->interface;
        struct dhcp_message *dhcp;
+       uint8_t *p;
+       ssize_t bytes;
 
        /* Allocate our buffer space for BPF.
         * We cannot do this until we have opened our socket as we don't
@@ -1199,13 +1201,11 @@ handle_packet(struct if_state *state, const struct options *options)
         * the first one fails for any reason, we can use the next. */
 
        dhcp = xmalloc(sizeof(*dhcp));
-
        do {
-               if (get_packet(iface, (uint8_t *)dhcp,
-                              state->buffer,
-                              &state->buffer_len, &state->buffer_pos) == -1)
+               bytes = get_packet(iface, (uint8_t *)dhcp, state->buffer,
+                                  &state->buffer_len, &state->buffer_pos);
+               if (bytes == -1)
                        break;
-
                if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
                        logger(LOG_DEBUG, "bogus cookie, ignoring");
                        continue;
@@ -1217,6 +1217,15 @@ handle_packet(struct if_state *state, const struct options *options)
                               dhcp->xid, state->xid);
                        continue;
                }
+               /* We should ensure that the packet is terminated correctly
+                * if we have space for the terminator */
+               if ((size_t)bytes < sizeof(struct dhcp_message)) {
+                       p = (uint8_t *)dhcp + bytes - 1;
+                       while (p > dhcp->options && *p == DHCP_PAD)
+                               p--;
+                       if (*p != DHCP_END)
+                               *++p = DHCP_END;
+               }
                if (handle_dhcp(state, &dhcp, options) == 0)
                        return 0;
        } while (state->buffer_pos != 0);