Skip to contentSkip to conversation

libfsimage: FAT: Fix unaligned access

PATCH New KUWAMURA Shin'ya 1 participant 1 message Aug 8, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfsimage: FAT: Fix unaligned access

Hi,

Using pygrub on IA64, the following messages output:

pygrub(5742): unaligned access to 0x600000000013515c, ip=0x2000000003b721f0 pygrub(5742): unaligned access to 0x600000000013515e, ip=0x2000000003b721f0 pygrub(5742): unaligned access to 0x6000000000135162, ip=0x2000000003b721f0 pygrub(5742): unaligned access to 0x6000000000135164, ip=0x2000000003b721f0 pygrub(5742): unaligned access to 0x6000000000135166, ip=0x2000000003b721f0

The ip indicates this line of tools/libfsimage/fat/fsys_fat.c:231:
next_cluster = * (unsigned long *) (FAT_BUF + (cached_pos >> 1));
If the partition is FAT16, this access causes an unaligned access. This patch fixes it.

Best Regards,

Signature · 1 line
  KUWAMURA Shin'ya
tools/libfsimage/fat/fsys_fat.c +3 -3
diff -r 7953164cebb6 tools/libfsimage/fat/fsys_fat.c
@@ -228,15 +228,15 @@ fat_read (fsi_file_t *ffi, char *buf, in
 	      if (!devread (ffi, sector, 0, FAT_CACHE_SIZE, (char*) FAT_BUF))
 		return 0;
 	    }
-	  next_cluster = * (unsigned long *) (FAT_BUF + (cached_pos >> 1));
+	  next_cluster = ((__u16 *) (FAT_BUF + (cached_pos >> 1)))[0];
 	  if (FAT_SUPER->fat_size == 3)
 	    {
 	      if (cached_pos & 1)
 		next_cluster >>= 4;
 	      next_cluster &= 0xFFF;
 	    }
-	  else if (FAT_SUPER->fat_size == 4)
-	    next_cluster &= 0xFFFF;
+	  else if (FAT_SUPER->fat_size > 4)
+	    next_cluster |= ((__u16 *) (FAT_BUF + (cached_pos >> 1)))[1] << 16;
 	  
 	  if (next_cluster >= FAT_SUPER->clust_eof_marker)
 	    return ret;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel