]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
fs/iso9660: Incorrect check for entry boundary
authorLidong Chen <lidong.chen@oracle.com>
Fri, 20 Jan 2023 19:39:41 +0000 (19:39 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 2 Feb 2023 18:44:56 +0000 (19:44 +0100)
An SL entry consists of the entry info and the component area.
The entry info should take up 5 bytes instead of sizeof(*entry).
The area after the first 5 bytes is the component area. It is
incorrect to use the sizeof(*entry) to check the entry boundary.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/fs/iso9660.c

index ecf6bbec966b1d5b7fce51639b0cca123e2153d1..64ea3d49576e3cf570dee4807929cc5449c1e649 100644 (file)
@@ -669,10 +669,23 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
   else if (grub_strncmp ("SL", (char *) entry->sig, 2) == 0)
     {
       unsigned int pos = 1;
+      unsigned int csize;
 
-      /* The symlink is not stored as a POSIX symlink, translate it.  */
-      while (pos + sizeof (*entry) < entry->len)
+      /* The symlink is not stored as a POSIX symlink, translate it. */
+      while ((pos + GRUB_ISO9660_SUSP_HEADER_SZ + 1) < entry->len)
        {
+         /*
+          * entry->len is GRUB_ISO9660_SUSP_HEADER_SZ + 1 (the FLAGS) +
+          * length of the "Component Area". The length of a component
+          * record is 2 (pos and pos + 1) plus the "Component Content",
+          * of which starts at pos + 2. entry->data[pos] is the
+          * "Component Flags"; entry->data[pos + 1] is the length
+          * of the component.
+          */
+          csize = entry->data[pos + 1] + 2;
+          if (GRUB_ISO9660_SUSP_HEADER_SZ + 1 + csize > entry->len)
+            break;
+
          /* The current position is the `Component Flag'.  */
          switch (entry->data[pos] & 30)
            {