From 11854e2eff8b15411bbbc35c95dc77d6a722cc6b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 16 Oct 2009 02:34:28 +0200 Subject: [PATCH] libblkid: add missing packed attributes This patch add __attribute__((packed)) to almost all superblock and disk label definitions. Well, in many cases this is not necessary, but it's a cheap way how to keep the code robust... Signed-off-by: Karel Zak --- shlibs/blkid/src/partitions/bsd.c | 2 +- shlibs/blkid/src/partitions/mac.c | 4 ++-- shlibs/blkid/src/partitions/sgi.c | 8 ++++---- shlibs/blkid/src/partitions/solaris_x86.c | 4 ++-- shlibs/blkid/src/partitions/unixware.c | 4 ++-- shlibs/blkid/src/superblocks/adaptec_raid.c | 2 +- shlibs/blkid/src/superblocks/cramfs.c | 4 ++-- shlibs/blkid/src/superblocks/ext.c | 2 +- shlibs/blkid/src/superblocks/gfs.c | 2 +- shlibs/blkid/src/superblocks/hpfs.c | 6 +++--- shlibs/blkid/src/superblocks/iso9660.c | 4 ++-- shlibs/blkid/src/superblocks/luks.c | 2 +- shlibs/blkid/src/superblocks/ntfs.c | 2 +- shlibs/blkid/src/superblocks/nvidia_raid.c | 2 +- shlibs/blkid/src/superblocks/reiserfs.c | 4 ++-- shlibs/blkid/src/superblocks/romfs.c | 2 +- shlibs/blkid/src/superblocks/silicon_raid.c | 2 +- shlibs/blkid/src/superblocks/squashfs.c | 2 +- shlibs/blkid/src/superblocks/swap.c | 2 +- shlibs/blkid/src/superblocks/sysv.c | 2 +- shlibs/blkid/src/superblocks/ubifs.c | 0 shlibs/blkid/src/superblocks/udf.c | 18 +++++++++++------- shlibs/blkid/src/superblocks/vfat.c | 8 ++++---- shlibs/blkid/src/superblocks/via_raid.c | 4 ++-- shlibs/blkid/src/superblocks/xfs.c | 2 +- shlibs/blkid/src/superblocks/zfs.c | 2 +- 26 files changed, 50 insertions(+), 46 deletions(-) mode change 100755 => 100644 shlibs/blkid/src/superblocks/ubifs.c diff --git a/shlibs/blkid/src/partitions/bsd.c b/shlibs/blkid/src/partitions/bsd.c index 829e3d01..9d0d7e5e 100644 --- a/shlibs/blkid/src/partitions/bsd.c +++ b/shlibs/blkid/src/partitions/bsd.c @@ -89,7 +89,7 @@ struct bsd_disklabel { uint8_t p_fstype; /* filesystem type, see below */ uint8_t p_frag; /* filesystem fragments per block */ uint16_t p_cpg; /* filesystem cylinders per group */ - } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ + } __attribute__((packed)) d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ } __attribute__((packed)); diff --git a/shlibs/blkid/src/partitions/mac.c b/shlibs/blkid/src/partitions/mac.c index c51b11ab..7f4a30b0 100644 --- a/shlibs/blkid/src/partitions/mac.c +++ b/shlibs/blkid/src/partitions/mac.c @@ -42,7 +42,7 @@ struct mac_partition { char processor[16]; /* identifies ISA of boot */ /* there is more stuff after this that we don't need */ -}; +} __attribute__((packed)); /* * Driver descriptor structure, in block 0 @@ -54,7 +54,7 @@ struct mac_driver_desc { uint32_t block_count; /* number of blocks on the device */ /* there is more stuff after this that we don't need */ -}; +} __attribute__((packed)); static inline unsigned char *get_mac_block( blkid_probe pr, diff --git a/shlibs/blkid/src/partitions/sgi.c b/shlibs/blkid/src/partitions/sgi.c index 5ebf9ded..c1094b78 100644 --- a/shlibs/blkid/src/partitions/sgi.c +++ b/shlibs/blkid/src/partitions/sgi.c @@ -47,7 +47,7 @@ struct sgi_device_parameter { uint16_t xylogics_gap2; uint16_t xylogics_readgate; uint16_t xylogics_writecont; -}; +} __attribute__((packed)); struct sgi_disklabel { uint32_t magic; /* magic number */ @@ -61,18 +61,18 @@ struct sgi_disklabel { unsigned char name[8]; /* name of volume */ uint32_t block_num; /* logical block number */ uint32_t num_bytes; /* how big, in bytes */ - } volume[15]; + } __attribute__((packed)) volume[15]; struct sgi_partition { uint32_t num_blocks; /* size in logical blocks */ uint32_t first_block; /* first logical block */ uint32_t type; /* type of this partition */ - } partitions[SGI_MAXPARTITIONS]; + } __attribute__((packed)) partitions[SGI_MAXPARTITIONS]; /* checksum is the 32bit 2's complement sum of the disklabel */ uint32_t csum; /* disk label checksum */ uint32_t padding; /* padding */ -}; +} __attribute__((packed)); static uint32_t count_checksum(struct sgi_disklabel *label) { diff --git a/shlibs/blkid/src/partitions/solaris_x86.c b/shlibs/blkid/src/partitions/solaris_x86.c index 964c406c..fe39a103 100644 --- a/shlibs/blkid/src/partitions/solaris_x86.c +++ b/shlibs/blkid/src/partitions/solaris_x86.c @@ -39,7 +39,7 @@ struct solaris_slice { uint16_t s_flag; /* permission flags */ uint32_t s_start; /* start sector no of partition */ uint32_t s_size; /* # of blocks in partition */ -}; +} __attribute__((packed)); struct solaris_vtoc { unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */ @@ -55,7 +55,7 @@ struct solaris_vtoc { unsigned int timestamp[SOLARIS_MAXPARTITIONS]; /* timestamp (unsupported) */ char v_asciilabel[128]; /* for compatibility */ -}; +} __attribute__((packed)); static int probe_solaris_pt(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/partitions/unixware.c b/shlibs/blkid/src/partitions/unixware.c index b4c8f6be..70b6626f 100644 --- a/shlibs/blkid/src/partitions/unixware.c +++ b/shlibs/blkid/src/partitions/unixware.c @@ -58,7 +58,7 @@ struct unixware_partition { uint16_t s_flags; /* permission flags */ uint32_t start_sect; /* starting sector */ uint32_t nr_sects; /* number of sectors */ -}; +} __attribute__((packed)); struct unixware_disklabel { uint32_t d_type; /* drive type */ @@ -91,7 +91,7 @@ struct unixware_disklabel { struct unixware_partition v_slice[UNIXWARE_MAXPARTITIONS]; /* partition */ - } vtoc; + } __attribute__((packed)) vtoc; }; static int probe_unixware_pt(blkid_probe pr, const struct blkid_idmag *mag) diff --git a/shlibs/blkid/src/superblocks/adaptec_raid.c b/shlibs/blkid/src/superblocks/adaptec_raid.c index 03f44ad7..d7a42a67 100644 --- a/shlibs/blkid/src/superblocks/adaptec_raid.c +++ b/shlibs/blkid/src/superblocks/adaptec_raid.c @@ -67,7 +67,7 @@ struct adaptec_metadata { uint32_t raidtbl; uint16_t raidline; uint8_t res9[0xF6]; -}; +} __attribute__((packed)); #define AD_SIGNATURE "DPTM" #define AD_MAGIC 0x37FC4D1E diff --git a/shlibs/blkid/src/superblocks/cramfs.c b/shlibs/blkid/src/superblocks/cramfs.c index 8a70f80b..b58ed08c 100644 --- a/shlibs/blkid/src/superblocks/cramfs.c +++ b/shlibs/blkid/src/superblocks/cramfs.c @@ -30,9 +30,9 @@ struct cramfs_super uint32_t edition; uint32_t blocks; uint32_t files; - } info; + } __attribute__((packed)) info; uint8_t name[16]; -}; +} __attribute__((packed)); static int probe_cramfs(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/ext.c b/shlibs/blkid/src/superblocks/ext.c index 4bccd2e7..b1bc2a8a 100644 --- a/shlibs/blkid/src/superblocks/ext.c +++ b/shlibs/blkid/src/superblocks/ext.c @@ -76,7 +76,7 @@ struct ext2_super_block { uint64_t s_mmp_block; uint32_t s_raid_stripe_width; uint32_t s_reserved[163]; -}; +} __attribute__((packed)); /* magic string */ #define EXT_SB_MAGIC "\123\357" diff --git a/shlibs/blkid/src/superblocks/gfs.c b/shlibs/blkid/src/superblocks/gfs.c index a7ff6615..8ad81bcb 100644 --- a/shlibs/blkid/src/superblocks/gfs.c +++ b/shlibs/blkid/src/superblocks/gfs.c @@ -56,7 +56,7 @@ struct gfs2_sb { struct gfs2_inum __pad3; /* Was quota inode in gfs1 */ struct gfs2_inum __pad4; /* Was licence inode in gfs1 */ uint8_t sb_uuid[16]; /* The UUID maybe 0 for backwards compat */ -}; +} __attribute__((packed)); static int probe_gfs(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/hpfs.c b/shlibs/blkid/src/superblocks/hpfs.c index 406c50aa..f9b851a4 100644 --- a/shlibs/blkid/src/superblocks/hpfs.c +++ b/shlibs/blkid/src/superblocks/hpfs.c @@ -39,20 +39,20 @@ struct hpfs_boot_block uint8_t sig_hpfs[8]; uint8_t pad[448]; uint8_t magic[2]; -}; +} __attribute__((packed)); struct hpfs_super_block { uint8_t magic[4]; uint8_t magic1[4]; uint8_t version; -}; +} __attribute__((packed)); struct hpfs_spare_super { uint8_t magic[4]; uint8_t magic1[4]; -}; +} __attribute__((packed)); #define HPFS_SB_OFFSET 0x2000 diff --git a/shlibs/blkid/src/superblocks/iso9660.c b/shlibs/blkid/src/superblocks/iso9660.c index ffab1daf..9f3ce2e6 100644 --- a/shlibs/blkid/src/superblocks/iso9660.c +++ b/shlibs/blkid/src/superblocks/iso9660.c @@ -30,7 +30,7 @@ struct iso_volume_descriptor { unsigned char unused[8]; unsigned char space_size[8]; unsigned char escape_sequences[8]; -}; +} __attribute__((packed)); #define ISO_SUPERBLOCK_OFFSET 0x8000 #define ISO_SECTOR_SIZE 0x800 @@ -47,7 +47,7 @@ struct high_sierra_volume_descriptor { unsigned char unused1; unsigned char system_id[32]; unsigned char volume_id[32]; -}; +} __attribute__((packed)); /* returns 1 if the begin of @ascii is equal to @utf16 string. */ diff --git a/shlibs/blkid/src/superblocks/luks.c b/shlibs/blkid/src/superblocks/luks.c index 486779d2..0af85b53 100644 --- a/shlibs/blkid/src/superblocks/luks.c +++ b/shlibs/blkid/src/superblocks/luks.c @@ -37,7 +37,7 @@ struct luks_phdr { uint8_t mkDigestSalt[LUKS_SALTSIZE]; uint32_t mkDigestIterations; uint8_t uuid[UUID_STRING_L]; -}; +} __attribute__((packed)); static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/ntfs.c b/shlibs/blkid/src/superblocks/ntfs.c index 21a2d8dd..eeba2b69 100644 --- a/shlibs/blkid/src/superblocks/ntfs.c +++ b/shlibs/blkid/src/superblocks/ntfs.c @@ -27,7 +27,7 @@ struct ntfs_super_block { uint8_t reserved2[3]; uint64_t volume_serial; uint16_t checksum; -}; +} __attribute__((packed)); struct master_file_table_record { uint32_t magic; diff --git a/shlibs/blkid/src/superblocks/nvidia_raid.c b/shlibs/blkid/src/superblocks/nvidia_raid.c index da989e07..8ce7f12a 100644 --- a/shlibs/blkid/src/superblocks/nvidia_raid.c +++ b/shlibs/blkid/src/superblocks/nvidia_raid.c @@ -21,7 +21,7 @@ struct nv_metadata { uint32_t size; uint32_t chksum; uint16_t version; -}; +} __attribute__((packed)); #define NVIDIA_SIGNATURE "NVIDIA" diff --git a/shlibs/blkid/src/superblocks/reiserfs.c b/shlibs/blkid/src/superblocks/reiserfs.c index 341470ab..4222a307 100644 --- a/shlibs/blkid/src/superblocks/reiserfs.c +++ b/shlibs/blkid/src/superblocks/reiserfs.c @@ -28,7 +28,7 @@ struct reiserfs_super_block { uint32_t rs_dummy4[5]; unsigned char rs_uuid[16]; char rs_label[16]; -}; +} __attribute__((packed)); struct reiser4_super_block { unsigned char rs4_magic[16]; @@ -36,7 +36,7 @@ struct reiser4_super_block { unsigned char rs4_uuid[16]; unsigned char rs4_label[16]; uint64_t rs4_dummy2; -}; +} __attribute__((packed)); static int probe_reiser(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/romfs.c b/shlibs/blkid/src/superblocks/romfs.c index 3b323717..91ef996f 100644 --- a/shlibs/blkid/src/superblocks/romfs.c +++ b/shlibs/blkid/src/superblocks/romfs.c @@ -21,7 +21,7 @@ struct romfs_super_block { unsigned char ros_magic[8]; uint32_t ros_dummy1[2]; unsigned char ros_volume[16]; -}; +} __attribute__((packed)); static int probe_romfs(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/silicon_raid.c b/shlibs/blkid/src/superblocks/silicon_raid.c index 08406b27..2144e505 100644 --- a/shlibs/blkid/src/superblocks/silicon_raid.c +++ b/shlibs/blkid/src/superblocks/silicon_raid.c @@ -35,7 +35,7 @@ struct silicon_metadata { uint16_t vendor_id; uint16_t minor_ver; uint16_t major_ver; -}; +} __attribute__((packed)); #define SILICON_MAGIC 0x2F000000 diff --git a/shlibs/blkid/src/superblocks/squashfs.c b/shlibs/blkid/src/superblocks/squashfs.c index 04f9e71c..45f10291 100644 --- a/shlibs/blkid/src/superblocks/squashfs.c +++ b/shlibs/blkid/src/superblocks/squashfs.c @@ -26,7 +26,7 @@ struct sqsh_super_block { uint32_t directory_table_start_2; uint16_t s_major; uint16_t s_minor; -}; +} __attribute__((packed)); static int probe_squashfs(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/swap.c b/shlibs/blkid/src/superblocks/swap.c index 5f7dd107..4fb4ab7a 100644 --- a/shlibs/blkid/src/superblocks/swap.c +++ b/shlibs/blkid/src/superblocks/swap.c @@ -28,7 +28,7 @@ struct swap_header_v1_2 { unsigned char volume[16]; uint32_t padding[117]; uint32_t badpages[1]; -}; +} __attribute__((packed)); #define PAGESIZE_MIN 0xff6 /* 4086 (arm, i386, ...) */ #define PAGESIZE_MAX 0xfff6 /* 65526 (ia64) */ diff --git a/shlibs/blkid/src/superblocks/sysv.c b/shlibs/blkid/src/superblocks/sysv.c index 82e6a1fa..530e860f 100644 --- a/shlibs/blkid/src/superblocks/sysv.c +++ b/shlibs/blkid/src/superblocks/sysv.c @@ -39,7 +39,7 @@ struct xenix_super_block { uint8_t s_fill[371]; uint32_t s_magic; uint32_t s_type; -}; +} __attribute__((packed)); #define SYSV_NICINOD 100 diff --git a/shlibs/blkid/src/superblocks/ubifs.c b/shlibs/blkid/src/superblocks/ubifs.c old mode 100755 new mode 100644 diff --git a/shlibs/blkid/src/superblocks/udf.c b/shlibs/blkid/src/superblocks/udf.c index 3b972ee9..55c96adb 100644 --- a/shlibs/blkid/src/superblocks/udf.c +++ b/shlibs/blkid/src/superblocks/udf.c @@ -28,28 +28,32 @@ struct volume_descriptor { uint16_t crc; uint16_t crc_len; uint32_t location; - } tag; + } __attribute__((packed)) tag; + union { struct anchor_descriptor { uint32_t length; uint32_t location; - } anchor; + } __attribute__((packed)) anchor; + struct primary_descriptor { uint32_t seq_num; uint32_t desc_num; struct dstring { uint8_t clen; uint8_t c[31]; - } ident; - } primary; - } type; -}; + } __attribute__((packed)) ident; + } __attribute__((packed)) primary; + + } __attribute__((packed)) type; + +} __attribute__((packed)); struct volume_structure_descriptor { uint8_t type; uint8_t id[5]; uint8_t version; -}; +} __attribute__((packed)); #define UDF_VSD_OFFSET 0x8000 diff --git a/shlibs/blkid/src/superblocks/vfat.c b/shlibs/blkid/src/superblocks/vfat.c index c47addbe..2ba7ded1 100644 --- a/shlibs/blkid/src/superblocks/vfat.c +++ b/shlibs/blkid/src/superblocks/vfat.c @@ -47,7 +47,7 @@ struct vfat_super_block { /* 52*/ unsigned char vs_magic[8]; /* 5a*/ unsigned char vs_dummy2[0x1fe - 0x5a]; /*1fe*/ unsigned char vs_pmagic[2]; -}; +} __attribute__((packed)); /* Yucky misaligned values */ struct msdos_super_block { @@ -73,7 +73,7 @@ struct msdos_super_block { /* 36*/ unsigned char ms_magic[8]; /* 3e*/ unsigned char ms_dummy2[0x1fe - 0x3e]; /*1fe*/ unsigned char ms_pmagic[2]; -}; +} __attribute__((packed)); struct vfat_dir_entry { uint8_t name[11]; @@ -87,7 +87,7 @@ struct vfat_dir_entry { uint16_t date_write; uint16_t cluster_low; uint32_t size; -}; +} __attribute__((packed)); struct fat32_fsinfo { uint8_t signature1[4]; @@ -96,7 +96,7 @@ struct fat32_fsinfo { uint32_t free_clusters; uint32_t next_cluster; uint32_t reserved2[4]; -}; +} __attribute__((packed)); /* maximum number of clusters */ #define FAT12_MAX 0xFF4 diff --git a/shlibs/blkid/src/superblocks/via_raid.c b/shlibs/blkid/src/superblocks/via_raid.c index b2d4efc5..fc974a70 100644 --- a/shlibs/blkid/src/superblocks/via_raid.c +++ b/shlibs/blkid/src/superblocks/via_raid.c @@ -27,10 +27,10 @@ struct via_metadata { uint32_t capacity_low; uint32_t capacity_high; uint32_t serial_checksum; - } array; + } __attribute__((packed)) array; uint32_t serial_checksum[8]; uint8_t checksum; -}; +} __attribute__((packed)); #define VIA_SIGNATURE 0xAA55 diff --git a/shlibs/blkid/src/superblocks/xfs.c b/shlibs/blkid/src/superblocks/xfs.c index ee4e338d..1399fe13 100644 --- a/shlibs/blkid/src/superblocks/xfs.c +++ b/shlibs/blkid/src/superblocks/xfs.c @@ -32,7 +32,7 @@ struct xfs_super_block { uint64_t xs_icount; uint64_t xs_ifree; uint64_t xs_fdblocks; -}; +} __attribute__((packed)); static int probe_xfs(blkid_probe pr, const struct blkid_idmag *mag) { diff --git a/shlibs/blkid/src/superblocks/zfs.c b/shlibs/blkid/src/superblocks/zfs.c index 02033af1..2d626427 100644 --- a/shlibs/blkid/src/superblocks/zfs.c +++ b/shlibs/blkid/src/superblocks/zfs.c @@ -24,7 +24,7 @@ struct zfs_uberblock { uint64_t ub_guid_sum; /* sum of all vdev guids */ uint64_t ub_timestamp; /* UTC time of last sync */ /*blkptr_t ub_rootbp;*/ /* MOS objset_phys_t */ -}; +} __attribute__((packed)); static int probe_zfs(blkid_probe pr, const struct blkid_idmag *mag) { -- 2.39.5