]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Fix overflow check for FDT_PROP in devicetree_get_compatible
authoranonymix007 <48598263+anonymix007@users.noreply.github.com>
Wed, 6 Nov 2024 20:03:12 +0000 (23:03 +0300)
committeranonymix007 <48598263+anonymix007@users.noreply.github.com>
Thu, 7 Nov 2024 19:52:29 +0000 (22:52 +0300)
src/boot/devicetree.c

index 842b96a97d9ff01100a5ba9c0cd30cd5d12b7b0f..2ec5ca28dd8b20af87ba09686066842ef47d2670 100644 (file)
@@ -131,6 +131,7 @@ static const char* devicetree_get_compatible(const void *dtb) {
 
         if (struct_off % sizeof(uint32_t) != 0)
                 return NULL;
+
         if (struct_size % sizeof(uint32_t) != 0 ||
             !ADD_SAFE(&end, struct_off, struct_size) ||
             end > strings_off)
@@ -150,7 +151,7 @@ static const char* devicetree_get_compatible(const void *dtb) {
                         break;
                 case FDT_PROP:
                         /* At least 3 words should present: len, name_off, c (nul-terminated string always has non-zero length) */
-                        if (i + 3 >= size_words || cursor[++i] != 0)
+                        if (i + 3 >= size_words)
                                 return NULL;
                         len = be32toh(cursor[++i]);
                         name_off = be32toh(cursor[++i]);