]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix valid length checks for single ipv4 addresses
authorRoy Marples <roy@marples.name>
Sat, 21 Apr 2012 11:59:24 +0000 (11:59 +0000)
committerRoy Marples <roy@marples.name>
Sat, 21 Apr 2012 11:59:24 +0000 (11:59 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index f39e7835cb256457c564dda1b2baa0eb4b604da1..742e352d5079dceb27f202c9c243617a69903855 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -272,6 +272,9 @@ valid_length(uint8_t option, int dl, int *type)
                    opt->type & (STRING | RFC3442 | RFC5969))
                        return 0;
 
+               if (opt->type & IPV4 && opt->type & ARRAY)
+                       return (dl % sizeof(uint32_t) == 0 ? 0 : -1);
+
                sz = 0;
                if (opt->type & (UINT32 | IPV4))
                        sz = sizeof(uint32_t);
@@ -279,9 +282,8 @@ valid_length(uint8_t option, int dl, int *type)
                        sz = sizeof(uint16_t);
                if (opt->type & UINT8)
                        sz = sizeof(uint8_t);
-               if (opt->type & (IPV4 | ARRAY))
-                       sz = dl % sizeof(uint32_t);
-               return (dl == sz ? 0 : -1);
+               /* If we don't know the size, assume it's valid */
+               return (sz == 0 || dl == sz ? 0 : -1);
        }
 
        /* unknown option, so let it pass */