Skip to content

Commit 24cce5c

Browse files
committed
fix(fs/iso9660): Correct improper cast for Rock Ridge flags
The previous code used a cast on entry->u.data to check for the GRUB_ISO9660_RR_DOT and GRUB_ISO9660_RR_DOTDOT flags, which was flagged with a FIXME comment. This commit resolves the improper cast by accessing the data through entry->u.version, providing a cleaner and more correct way to read the Rock Ridge flags. Signed-off-by: Alessio Attilio <[email protected]>
1 parent 6482f2e commit 24cce5c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

EDK2/efiffs/org/grub/grub-core/fs/iso9660.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ set_rockridge (struct grub_iso9660_data *data)
424424

425425
/* The 2nd data byte stored how many bytes are skipped every time
426426
to get to the SUA (System Usage Area). */
427-
data->susp_skip = entry->u.data[1 + 2];
427+
data->susp_skip = *(&entry->u.version + 1 + 2);
428428
entry = (struct grub_iso9660_susp_entry *) ((char *) entry + entry->len);
429429

430430
/* Iterate over the entries in the SUA area to detect
@@ -561,12 +561,10 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
561561
/* The filename in the rock ridge entry. */
562562
if (grub_strncmp ("NM", (char *) entry->sig, 2) == 0)
563563
{
564-
/* The flags are stored at the data position 0, here the
565-
filename type is stored. */
566-
/* FIXME: Fix this slightly improper cast. */
567-
if (entry->u.data[1 + 0] & GRUB_ISO9660_RR_DOT)
564+
/* The flags are stored in the byte following the version number. */
565+
if (entry->u.version & GRUB_ISO9660_RR_DOT)
568566
ctx->filename = (char *) ".";
569-
else if (entry->u.data[1 + 0] & GRUB_ISO9660_RR_DOTDOT)
567+
else if (entry->u.version & GRUB_ISO9660_RR_DOTDOT)
570568
ctx->filename = (char *) "..";
571569
else if (entry->len >= 5)
572570
{
@@ -590,7 +588,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
590588
return grub_errno;
591589
}
592590
ctx->filename_alloc = 1;
593-
grub_memcpy (ctx->filename + off, (char *) &entry->u.data[1 + 1], csize);
591+
grub_memcpy (ctx->filename + off, (char *) &entry->u.version + 1 + 1, csize);
594592
ctx->filename[off + csize] = '\0';
595593
}
596594
}
@@ -599,7 +597,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
599597
{
600598
/* At position 0 of the PX record the st_mode information is
601599
stored (little-endian). */
602-
grub_uint32_t mode = ((entry->u.data[1 + 0] + (entry->u.data[1 + 1] << 8))
600+
grub_uint32_t mode = ((*(&entry->u.version + 1 + 0) + (*(&entry->u.version + 1 + 1) << 8))
603601
& GRUB_ISO9660_FSTYPE_MASK);
604602

605603
switch (mode)
@@ -625,7 +623,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
625623
while (pos + sizeof (*entry) < entry->len)
626624
{
627625
/* The current position is the `Component Flag'. */
628-
switch (entry->u.data[1 + pos] & 30)
626+
switch (*(&entry->u.version + 1 + pos) & 30)
629627
{
630628
case 0:
631629
{
@@ -634,9 +632,9 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
634632
Record'. */
635633
if (ctx->symlink && !ctx->was_continue)
636634
add_part (ctx, "/", 1);
637-
add_part (ctx, (char *) &entry->u.data[1 + pos + 2],
638-
entry->u.data[1 + pos + 1]);
639-
ctx->was_continue = (entry->u.data[1 + pos] & 1);
635+
add_part (ctx, (char *) &entry->u.version + 1 + pos + 2,
636+
*(&entry->u.version + 1 + pos + 1));
637+
ctx->was_continue = (*(&entry->u.version + 1 + pos) & 1);
640638
break;
641639
}
642640

@@ -654,7 +652,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
654652
}
655653
/* In pos + 1 the length of the `Component Record' is
656654
stored. */
657-
pos += entry->u.data[1 + pos + 1] + 2;
655+
pos += *(&entry->u.version + 1 + pos + 1) + 2;
658656
}
659657

660658
/* Check if `grub_realloc' failed. */

0 commit comments

Comments
 (0)