chiark / gitweb /
sd-dhcp: make sure we can not fill options so much that there is no space for END
authorTom Gundersen <teg@jklm.no>
Wed, 21 May 2014 13:27:53 +0000 (15:27 +0200)
committerTom Gundersen <teg@jklm.no>
Wed, 21 May 2014 13:27:53 +0000 (15:27 +0200)
src/libsystemd-network/dhcp-option.c
src/libsystemd-network/test-dhcp-option.c

index 68950923ddd9ea8265b4ae7cd509aa7b31b316fe..24f678c100b41b39fe84b3cbd0cd9ba71e1e009f 100644 (file)
@@ -31,6 +31,10 @@ int dhcp_option_append(uint8_t options[], size_t size, size_t *offset,
         assert(options);
         assert(offset);
 
+        if (code != DHCP_OPTION_END)
+                /* always make sure there is space for an END option */
+                size --;
+
         switch (code) {
 
         case DHCP_OPTION_PAD:
index eaf6a535e6fe21bcdd7e48e4c99ae7e5fbfae785..3dd7102d821cdc115fa4b137b8f7ecaa4300faf4 100644 (file)
@@ -85,7 +85,7 @@ static void test_invalid_buffer_length(void)
 static void test_message_init(void)
 {
         _cleanup_free_ DHCPMessage *message = NULL;
-        size_t optlen = 3, optoffset;
+        size_t optlen = 4, optoffset;
         size_t len = sizeof(DHCPMessage) + optlen;
         uint8_t *magic;