Commit Graph

35 Commits

Author SHA1 Message Date
Peter Jones f725fa7cb2 calloc: Use calloc() at most places
This modifies most of the places we do some form of:

  X = malloc(Y * Z);

to use calloc(Y, Z) instead.

Among other issues, this fixes:
  - allocation of integer overflow in grub_png_decode_image_header()
    reported by Chris Coulson,
  - allocation of integer overflow in luks_recover_key()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_lvm_detect()
    reported by Chris Coulson.

Fixes: CVE-2020-14308

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-07-29 16:55:47 +02:00
Vladimir Serbinenko ad4bfeec5c Change fs functions to add fs_ prefix
This avoid conflict with gnulib

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-04-09 10:03:29 +10:00
Vladimir Serbinenko 7e47e27bd8 Add gcc_struct to all packed structures when compiling with mingw.
Just "packed" doesn't always pack the way we expect.
2013-12-15 14:14:30 +01:00
Vladimir 'phcoder' Serbinenko bf919aa977 * grub-core/fs/affs.c (grub_affs_create_node): Fix uninited value
warning.
2013-10-18 16:47:30 +02:00
Colin Watson 4eb8b75659 Remove nested functions from disk and file read hooks.
* include/grub/disk.h (grub_disk_read_hook_t): New type.
	(struct grub_disk): Add read_hook_data member.
	* include/grub/file.h (struct grub_file): Likewise.
	* include/grub/fshelp.h (grub_fshelp_read_file): Add read_hook_data
	argument.

	Update all callers.
2013-02-27 17:19:15 +01:00
Colin Watson fc524edf65 Remove nested functions from filesystem directory iterators.
* include/grub/fs.h (grub_fs_dir_hook_t): New type.
(struct grub_fs.dir): Add hook_data argument.

Update all implementations and callers.
2013-01-21 01:33:46 +00:00
Vladimir 'phcoder' Serbinenko b78c312722 * grub-core/fs/affs.c (grub_affs_mount): Support AFFS bootblock in
sector 1.
2012-09-26 09:33:41 +02:00
Vladimir 'phcoder' Serbinenko fd8ed4c5c5 * grub-core/fs/affs.c (grub_affs_file): New field hardlink.
(GRUB_AFFS_FILETYPE_HARDLINK): New enum value.
	(grub_affs_iterate_dir): Handle hardlinks.
2012-05-27 00:45:41 +02:00
Vladimir 'phcoder' Serbinenko a4469c8806 * grub-core/fs/affs.c (grub_affs_mtime): Add missing grub_dl_ref. 2012-05-21 22:07:28 +02:00
Vladimir 'phcoder' Serbinenko 33eca6e005 * grub-core/fs/affs.c (grub_affs_read_symlink): Fix handling of long
symlinks. Replace leading colon with a slash.
2012-05-12 13:44:48 +02:00
Vladimir 'phcoder' Serbinenko f417ed0432 Fix wrapped HFS+ handling.
* grub-core/fs/fshelp.c (grub_fshelp_read_file): New argument
	blocks_start. All users updated.
	* grub-core/fs/hfsplus.c (grub_hfsplus_read_block): Don't add
	wrapping offset.
	(grub_hfsplus_read_file): Pass embedding offset to fshelp_read_file.
2012-05-09 13:02:59 +02:00
Vladimir 'phcoder' Serbinenko 6ae485aaef Fix AFFS with non-512B blocks.
* grub-core/fs/affs.c (grub_affs_rblock): Make type uint32_t.
	(AFFS_MAX_LOG_BLOCK_SIZE): New definition.
	(grub_affs_data): Replace blocksize with log_blocksize.
	(grub_affs_read_block): Fix non-512B blocks.
	(grub_affs_read_symlink): Likewise.
	(grub_affs_iterate_dir): Likewise. Fix freeing corruption.
	(grub_affs_read): Fix non-512B blocks.
	(grub_affs_label): Likewise.
	(grub_affs_mtime): Likewise.
	(grub_affs_mount): Fix block detection routine.
2012-05-08 04:38:19 +02:00
Vladimir 'phcoder' Serbinenko d20fab8471 Add filesystem mtime to AFFS.
* grub-core/fs/affs.c (grub_affs_file): Make type unsigned.
	(aftime2ctime): New function.
	(grub_affs_dir): Use aftime2ctime.
	(grub_affs_label): Fix return value.
	(grub_affs_mtime): New function.
	(grub_affs_fs): Add mtime.
2012-05-08 01:51:34 +02:00
Vladimir 'phcoder' Serbinenko e87b10f5d6 * grub-core/fs/affs.c (grub_affs_read_symlink): Convert latin1 into
UTF-8.
2012-05-07 22:00:19 +02:00
Vladimir 'phcoder' Serbinenko 2f48221f5c * grub-core/fs/affs.c (grub_affs_iterate_dir): Mark as case insensitive. 2012-05-07 19:09:02 +02:00
Vladimir 'phcoder' Serbinenko 62ace64dd9 * grub-core/fs/affs.c (grub_affs_read_block): Fix theoretical overflow. 2012-05-06 16:18:00 +02:00
Vladimir 'phcoder' Serbinenko e1e49678b9 * util/grub-install.in: Clarify strings.
Fix source dir check.
2012-02-27 21:36:58 +01:00
Vladimir 'phcoder' Serbinenko 84f9d341b0 * grub-core/fs/affs.c (grub_affs_read_block): Avoid <= in loop
condition to avoid possibly infinite loops.
	* grub-core/lib/pbkdf2.c (grub_crypto_pbkdf2): Likewise.
	* grub-core/lib/xzembed/xz_dec_bcj.c (bcj_powerpc): Likewise.
2012-02-22 05:22:39 +01:00
Vladimir 'phcoder' Serbinenko 9c2710789f Eliminate grub_min/grub_max prone to overflow usage.
* grub-core/bus/usb/usbhub.c (grub_usb_add_hub): Eliminate grub_min.
	(poll_nonroot_hub): Likewise.
	* grub-core/fs/affs.c (grub_affs_iterate_dir): Likewise.
	(grub_affs_label): Likewise.
	* grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Likewise.
	* grub-core/fs/hfs.c (grub_hfs_dir): Likewise.
	(grub_hfs_label): Likewise.
	* grub-core/fs/hfsplus.c (grub_hfsplus_cmp_catkey): Likewise.
	* grub-core/fs/zfs/zfs.c (MIN): Remove.
	(zap_leaf_array_equal): Use grub_size. Remove MIN.
	(zap_leaf_array_get): Likewise.
	(dnode_get_path): Likewise.
	* grub-core/io/lzopio.c (grub_lzopio_read): Eliminate grub_min.
	* grub-core/io/xzio.c (grub_xzio_read): Likewise.
	* grub-core/script/execute.c (grub_script_break): Likewise.
	* grub-core/script/lexer.c (grub_script_lexer_record): Eliminate
	grub_max.
	* grub-core/script/yylex.l (grub_lexer_yyrealloc): Likewise.
	* include/grub/misc.h (grub_min): Removed.
	(grub_max): Likewise.
2012-01-14 15:44:34 +01:00
Vladimir 'phcoder' Serbinenko 5c827cf971 * grub-core/fs/affs.c (grub_affs_bblock): Revert flags.
(GRUB_AFFS_FLAG_FFS): Put back where it was.
	(grub_affs_mount): Revert the correct version checking.
2012-01-11 12:53:38 +01:00
Vladimir 'phcoder' Serbinenko 2ae254de13 * grub-core/fs/affs.c (grub_affs_label): Interpret label as latin1. 2011-12-25 22:07:15 +01:00
Vladimir 'phcoder' Serbinenko 309e535231 AFFS never uses unicode.
* include/grub/charset.h (GRUB_MAX_UTF8_PER_LATIN1): New const.
	(grub_latin1_to_utf8): New inline function.
	* grub-core/fs/affs.c (grub_affs_iterate_dir): Convert latin1 to UTF8.
2011-12-14 09:52:00 +01:00
Vladimir 'phcoder' Serbinenko 52b656c037 Several AFFS fixes.
* grub-core/fs/affs.c (grub_affs_bblock): Replace flags with version.
	(GRUB_AFFS_FLAG_FFS): Removed.
	(GRUB_AFFS_SYMLINK_SIZE): Likewise.
	(GRUB_AFFS_FILETYPE_DIR): Make positive and unsigned.
	(GRUB_AFFS_FILETYPE_DIR), (GRUB_AFFS_FILETYPE_REG): Fix a mix-up.
	(grub_fshelp_node): Make block 32-bit.
	Add block_cache and last_block_cache.
	(grub_affs_read_block): Fill and use block cache.
	(grub_affs_read_file): Removed.
	(grub_affs_mount): Zero-fill node. Fix version check. Don't reread
	boot block.
	(grub_affs_read_symlink): Fix symlink size. Add a \0 at the end for
	safety.
	(grub_affs_iterate_dir): Use more appropriate types. Zero-fill allocated
	space.
	(grub_affs_close): Free block cache.
	(grub_affs_read): Use grub_fshelp_read_file directly.
2011-11-09 11:43:39 +01:00
Vladimir 'phcoder' Serbinenko 366e34fa5a Fix few obvious type discrepancies.
* grub-core/fs/affs.c (grub_affs_read_file): Use grub_off_t for offset.
	* grub-core/fs/afs.c (grub_afs_read_file): Likewise.
	* grub-core/fs/fshelp.c (grub_fshelp_find_file): Remove leftover
	variable.
	* grub-core/fs/hfs.c (grub_hfs_read_file): Use grub_off_t for offset
	and connected types.
	* grub-core/fs/nilfs2.c (grub_nilfs2_read_file): Use grub_off_t for
	offset.
	(grub_nilfs2_iterate_dir): Use grub_off_t for fpos.
	* grub-core/fs/sfs.c (grub_sfs_read_file): Use grub_off_t for offset.
	* grub-core/fs/ufs.c (grub_ufs_read_file): Use grub_off_t for offset
	and connected types.
2011-10-16 11:57:48 +02:00
Vladimir 'phcoder' Serbinenko bf947d36e3 Use full 64-bit division.
* grub-core/kern/misc.c (grub_divmod64_full): Renamed to ...
	(grub_divmod64): ... this.
	* include/grub/misc.h (grub_divmod64): Removed. All users switch to full
	version.
2011-05-18 15:35:19 +02:00
Vladimir 'phcoder' Serbinenko b756f75f07 Several FS mtime support.
* grub-core/fs/affs.c (grub_affs_time): New struct.
	(grub_affs_file): New field mtime.
	(grub_fshelp_node): Changed 'block' and 'parent' to more appropriate
	type. Removed 'size'. New field 'di'. All users updated.
	(grub_affs_mount): Simplify checsum checking.
	(grub_affs_iterate_dir): New helper grub_affs_create_node.
	(grub_affs_dir): Handle mtime.
	* grub-core/fs/cpio.c (grub_cpio_find_file): Handle mtime.
	(grub_cpio_dir): Likewise.
	* grub-core/fs/hfs.c (grub_hfs_dirrec): New fields 'ctime' and 'mtime'.
	(grub_hfs_filerec): New field mtime.
	(grub_hfs_dir): Handle mtime.
	(grub_hfs_mtime): New function.
	(grub_hfs_fs): Register grub_hfs_mtime.
	* grub-core/fs/iso9660.c (grub_iso9660_date2): New struct.
	(grub_iso9660_dir): New field mtime.
	(grub_fshelp_node): New field dirent.
	(iso9660_to_unixtime): New function.
	(iso9660_to_unixtime2): Likewise.
	(grub_iso9660_read_symlink): Use node->dirent.
	(grub_iso9660_iterate_dir): Likewise.
	(grub_iso9660_dir): Set mtime.
	(grub_iso9660_mtime): New function.
	(grub_iso9660_fs): Register grub_iso9660_mtime.
	* grub-core/fs/jfs.c (grub_jfs_time): New struct.
	(grub_jfs_inode): New fields atime, ctime and mtime.
	(grub_jfs_dir): Set mtime.
	* grub-core/fs/minix.c (grub_minix_dir): Likewise.
	* grub-core/fs/ntfs.c (list_file): Set mtime.
	(grub_ntfs_dir): Likewise.
	* grub-core/fs/reiserfs.c (grub_fshelp_node): New field 'mtime'.
	(grub_reiserfs_iterate_dir): Set mtime.
	(grub_reiserfs_dir): Likewise.
	* grub-core/fs/sfs.c (grub_sfs_obj): New field mtime.
	(grub_fshelp_node): Likewise.
	(grub_sfs_iterate_dir): Set mtime.
	(grub_sfs_dir): Likewise.
	* grub-core/fs/udf.c (grub_udf_dir): Set mtime.
	* grub-core/fs/xfs.c (grub_xfs_time): New struct.
	(grub_xfs_inode): New fields atime, mtime, ctime.
	(grub_xfs_dir): Set mtime.
	* include/grub/datetime.h (grub_datetime2unixtime): New function.
	* include/grub/hfs.h (grub_hfs_sblock): New fields ctime and mtime.
	* include/grub/ntfs.h (grub_fshelp_node): New field mtime.

	Support UDF symlinks.

	* grub-core/fs/udf.c (grub_udf_iterate_dir): Handle symlinks.
	(grub_ufs_read_symlink): New function. All users updated.

	Check amiga partmap checksum.

	* grub-core/partmap/amiga.c (grub_amiga_rdsk): Pad to 128 bytes.
	(grub_amiga_partition): Likewise.
	(amiga_partition_map_checksum): New function.
	(amiga_partition_map_iterate): Check checksum.
2011-05-15 12:23:54 +02:00
Vladimir 'phcoder' Serbinenko e745cf0ca6 Implement automatic module license checking according to new GNU
guidelines.

	* grub-core/kern/dl.c (grub_dl_check_license): New function.
	(grub_dl_load_core): Use grub_dl_check_license.
	* include/grub/dl.h (GRUB_MOD_SECTION): New macro.
	(GRUB_MOD_LICENSE): Likewise.
	(GRUB_MOD_DUAL_LICENSE): Likewise.
	All modules updated.
2011-04-11 23:01:51 +02:00
Vladimir 'phcoder' Serbinenko b9cd13659c Simplify the AFFS checksum computation. 2010-12-31 15:22:36 +01:00
Vladimir 'phcoder' Serbinenko 6c85b743f5 * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock
rather than assuming than rootblock is exactly in the middle.
	(grub_affs_label): Likewise.
2010-12-19 00:52:18 +01:00
Vladimir 'phcoder' Serbinenko a2a08a35bf * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set
reserved_first_sector to 0.
	* grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise.
	* grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise.
	* grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise.
2010-12-19 00:49:52 +01:00
Vladimir 'phcoder' Serbinenko 790aaa8c9f AFFS mtime support 2010-12-11 22:02:22 +01:00
Vladimir 'phcoder' Serbinenko e21c356413 restructure AFFS fshelp_node-related code 2010-12-11 21:59:22 +01:00
Vladimir 'phcoder' Serbinenko 9959c6a70b Fix AFFS rootblock detection 2010-12-11 21:15:25 +01:00
Vladimir 'phcoder' Serbinenko 80113a6258 declare AFFS, CPIO, TAR and XFS as non-installable explicitly 2010-12-11 18:21:39 +01:00
BVK Chaitanya 8c41176882 automake commit without merge history 2010-05-06 11:34:04 +05:30