* Raw disk label. For DOS-type partition tables the MBR,
* with descriptions of the primary partitions.
*/
-unsigned char MBRbuffer[MAX_SECTOR_SIZE];
+unsigned char *MBRbuffer;
/*
* per partition table entry data
}
}
+/*
+ * Please, always use allocated buffer if you want to cast the buffer to
+ * any struct -- cast non-allocated buffer to any struct is against
+ * strict-aliasing rules. --kzak 16-Oct-2009
+ */
+static void init_mbr_buffer(void)
+{
+ if (MBRbuffer)
+ return;
+
+ MBRbuffer = calloc(1, MAX_SECTOR_SIZE);
+ if (!MBRbuffer)
+ fatal(out_of_memory);
+}
+
+void zeroize_mbr_buffer(void)
+{
+ if (MBRbuffer)
+ memset(MBRbuffer, 0, MAX_SECTOR_SIZE);
+}
+
/*
* Read MBR. Returns:
* -1: no 0xaa55 flag present (possibly entire disk BSD)
" be used with one specified device\n"));
#endif
+ init_mbr_buffer();
+
if (optl) {
nowarn = 1;
type_open = O_RDONLY;
extern unsigned int read_int(unsigned int low, unsigned int dflt,
unsigned int high, unsigned int base, char *mesg);
-extern unsigned char MBRbuffer[MAX_SECTOR_SIZE];
+extern unsigned char *MBRbuffer;
+extern void zeroize_mbr_buffer(void);
+
extern unsigned int heads, cylinders, sector_size;
extern unsigned long long sectors;
extern char *partition_type(unsigned char type);
aixlabel->magic = 0;
aix_label = 0;
partitions = 4;
- memset( MBRbuffer, 0, sizeof(MBRbuffer) ); /* avoid fdisk cores */
+ zeroize_mbr_buffer();
return;
}
maclabel->magic = 0;
mac_label = 0;
partitions = 4;
- memset( MBRbuffer, 0, sizeof(MBRbuffer) ); /* avoid fdisk cores */
+ zeroize_mbr_buffer();
return;
}
}
}
- memset(MBRbuffer, 0, sizeof(MBRbuffer));
+ zeroize_mbr_buffer();
sgilabel->magic = SSWAP32(SGI_LABEL_MAGIC);
sgilabel->boot_part = SSWAP16(0);
sgilabel->swap_part = SSWAP16(1);
#else
other_endian = 0;
#endif
- memset(MBRbuffer, 0, sizeof(MBRbuffer));
+ zeroize_mbr_buffer();
sunlabel->magic = SSWAP16(SUN_LABEL_MAGIC);
sunlabel->sanity = SSWAP32(SUN_LABEL_SANE);
sunlabel->version = SSWAP32(SUN_LABEL_VERSION);