Commit graph

40 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
157f9a9cca fs/ntfs: Add sizes sanity checks.
Found by: Coverity scan.
2015-01-25 20:32:31 +01:00
Vladimir Serbinenko
bc0ecd7104 fs/ntfs: Add missing free.
Found by: Coverity scan.
2015-01-25 20:32:31 +01: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 Serbinenko
f169f65e75 * grub-core/fs/hfspluscomp.c (hfsplus_read_compressed_real): Call
file_progress_read_hook.
	* grub-core/fs/ntfscomp.c (hfsplus_read_compressed_real): Likewise.
2013-11-02 16:30:53 +01:00
Vladimir 'phcoder' Serbinenko
067e6ae74d * grub-core/fs/ntfs.c (grub_ntfs_mount): Remove redundant check.
Saves 5 bytes on compressed image.
2013-10-21 13:14:38 +02:00
Vladimir 'phcoder' Serbinenko
64a6c791e1 * grub-core/fs/ntfs.c: Move common UTF-16 handling to a separate
function get_utf8.

	Saves 379 bytes on compressed image.
2013-10-21 13:04:41 +02:00
Vladimir 'phcoder' Serbinenko
979d9f521d * grub-core/fs/ntfs.c: Handle 48-bit MFT no. 2013-10-21 12:58:38 +02:00
Vladimir 'phcoder' Serbinenko
1437da5440 * grub-core/fs/ntfs.c (read_run_data): Rewrite using bitfields.
Saves 40 bytes on compressed image.
2013-10-21 04:05:23 +02:00
Vladimir 'phcoder' Serbinenko
d9ee2269c8 * grub-core/fs/ntfs.c (grub_ntfs_iterate_dir): Use grub_uint8_t for
mask rather than 64-bit type.

	Saves 20 bytes on compressed image.
2013-10-21 03:23:57 +02:00
Vladimir 'phcoder' Serbinenko
63efa602ff * grub-core/fs/ntfs.c (read_data): Move code for compressed data to ...
* grub-core/fs/ntfscomp.c (ntfscomp): ... here.
2013-10-21 02:48:19 +02:00
Vladimir 'phcoder' Serbinenko
1ba6b9b96f * grub-core/fs/ntfs.c: Add comment about fixed allocation size. 2013-10-20 18:48:06 +02:00
Vladimir 'phcoder' Serbinenko
88ce4cd7f6 * grub-core/fs/ntfs.c: Remove variable length arrays.
Increases ntfs.mod by 64 bytes (but decreases by 3 when
	compressed).
2013-10-20 17:35:17 +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
535714bdcf * grub-core/fs/ntfs.c: Ue more appropriate types.
* grub-core/fs/ntfscomp.c: Likewise.
	* include/grub/ntfs.h: Likewise.
2013-01-11 07:41:05 +01:00
Vladimir 'phcoder' Serbinenko
033d0b4b0b * grub-core/fs/ntfs.c: Eliminate useless divisions in favor of shifts.
* grub-core/fs/ntfscomp.c: Likewise.
	* include/grub/ntfs.h (grub_ntfs_data): Replace spc with log_spc.
	(grub_ntfs_comp): Likewise.
2013-01-05 17:36:04 +01:00
Vladimir 'phcoder' Serbinenko
80a3dc3fb4 * grub-core/fs/ntfs.c (list_file): Set mtime to correct value. 2012-05-27 01:00:46 +02:00
Vladimir 'phcoder' Serbinenko
c6666ba687 * grub-core/fs/ntfs.c (read_data): Prevent overflow.
(read_attr): Ensure that we read start of possibly compressed block.
2012-05-15 17:17:06 +02:00
Vladimir 'phcoder' Serbinenko
2e57f28fc7 * grub-core/fs/bfs.c (mount): Improve filesystem detection reliability.
* grub-core/fs/ext2.c (grub_ext2_mount): Likewise.
	* grub-core/fs/hfs.c (grub_hfs_mount): Likewise.
	* grub-core/fs/hfsplus.c (grub_hfsplus_mount): Likewise.
	* grub-core/fs/jfs.c (grub_jfs_mount): Likewise.
	* grub-core/fs/minix.c (grub_minix_mount): Likewise.
	* grub-core/fs/ntfs.c (grub_ntfs_mount): Likewise.
	* grub-core/fs/romfs.c (grub_romfs_mount): Likewise.
	* grub-core/fs/xfs.c (grub_xfs_mount): Likewise.
2012-05-12 13:31:05 +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
1b8463f2c4 Fix errors on compressed NTFS with 512B clusters.
* include/grub/ntfs.h (grub_ntfscomp_func_t): Use appropriately sized
	types.
	* grub-core/fs/ntfs.c (grub_ntfs_read): Return correct -1 on error and
	not 0.
	* grub-core/fs/ntfscomp.c (read_block): Use appropriately-sized types.
	Relax check for inline extents.
	(ntfscomp): Return correct -1 on error and not 0.
2012-05-04 17:37:17 +02:00
Vladimir 'phcoder' Serbinenko
986748ce79 * grub-core/fs/ntfs.c (grub_ntfs_mount): Support 256-byte sectors,
as long as cluster size is multiple of 512 bytes.
2012-04-25 11:56:24 +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
e7b02f9ec0 * grub-core/fs/ntfs.c (locate_attr): Avoid set in if.
(grub_ntfs_iterate_dir): Likewise.
2012-02-12 18:47:46 +01:00
Vladimir 'phcoder' Serbinenko
d61386e21d Improve string. Gettextize. 2012-02-12 15:25:25 +01:00
Vladimir 'phcoder' Serbinenko
b508af6989 Support 4K-sector NTFS.
* include/grub/ntfs.h (GRUB_NTFS_MAX_MFT): Increase to 8.
	(grub_ntfs_data): Remove blocksize.
	* grub-core/fs/ntfs.c (fixup): Fix size comparison.
	Remove data argument. All users updated.
2012-01-20 15:01:35 +01:00
Vladimir 'phcoder' Serbinenko
58acccd645 * grub-core/fs/ntfs.c (u16at): Make into inline function.
Handle unaligned pointers.
	(u32at): Likewise.
	(u64at): Likewise.
	(fixup): Use byte access instead of v16at.
	(find_attr): Fix imporper usage of v32at.
	(read_data): Likewise.
	(list_file): Handle byte-swapping and unaligned strings.
	(grub_ntfs_label): Likewise.
2011-12-13 14:17:24 +01:00
Vladimir 'phcoder' Serbinenko
bf3a385792 Add missing const qualifiers.
* grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const.
	* grub-core/commands/lspci.c (grub_pci_classname): Likewise.
	* grub-core/commands/menuentry.c (hotkey_aliases): Likewise.
	* grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise.
	(grub_lvm_check_flag): Likewise.
	* grub-core/efiemu/i386/coredetect.c
	(grub_efiemu_get_default_core_name): Likewise
	* grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise.
	* grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise.
	* grub-core/fs/ntfs.c (fixup): Likewise.
	* grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise.
	* grub-core/fs/zfs/zfs.c (decomp_entry): Likewise.
	(fzap_lookup): Likewise.
	(zap_lookup): Likewise.
	* grub-core/gnulib/regcomp.c (init_dfa): Likewise.
	* grub-core/lib/legacy_parse.c (check_option): Likewise.
	* grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise.
	* grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise.
	(grub_freebsd_add_meta_module): Likewise.
	(grub_cmd_freebsd_module): Likewise.
	* grub-core/loader/i386/xnu.c (tbl_alias): Likewise.
	* grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise.
	(grub_xnu_writetree_get_size): Likewise.
	(grub_xnu_writetree_toheap_real): Likewise.
	(grub_xnu_find_key): Likewise.
	(grub_xnu_create_key): Likewise.
	(grub_xnu_create_value): Likewise.
	(grub_xnu_register_memory): Likewise.
	(grub_xnu_check_os_bundle_required): Likewise.
	(grub_xnu_scan_dir_for_kexts): Likewise.
	(grub_xnu_load_kext_from_dir): Likewise.
	* grub-core/normal/color.c (color_list): Likewise.
	* grub-core/normal/completion.c (current_word): Likewise.
	* grub-core/normal/menu_entry.c (insert_string): Likewise.
	* grub-core/term/serial.c (grub_serial_find): Likewise.
	* grub-core/term/tparm.c (grub_terminfo_tparm): Likewise.
	* include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name):
	Likewise.
	* include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise.
	(grub_freebsd_add_meta_module): Likewise.
	* include/grub/lib/arg.h (grub_arg_option): Likewise.
	* include/grub/net.h (grub_net_card_driver): Likewise.
	(grub_net_card): Likewise.
	(grub_net_app_protocol): Likewise.
	* include/grub/parttool.h (grub_parttool_argdesc): Likewise.
	* include/grub/serial.h (grub_serial_find): Likewise.
	* include/grub/tparm.h (grub_terminfo_tparm): Likewise.
	* include/grub/xnu.h (grub_xnu_create_key): Likewise.
	(grub_xnu_create_value): Likewise.
	(grub_xnu_find_key): Likewise.
	(grub_xnu_scan_dir_for_kexts): Likewise.
	(grub_xnu_load_kext_from_dir): Likewise.

	* include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ...
	* grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here.
	* include/grub/zfs/zio_checksum.h (zio_checksum_info):
	Moved from here ...
	* grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 16:20:13 +01:00
Vladimir 'phcoder' Serbinenko
53dc859065 * grub-core/fs/ntfs.c (grub_ntfs_read_symlink): Stylistic fix. Remove
leftover debug printf.
2011-11-11 17:18:34 +01:00
Vladimir 'phcoder' Serbinenko
5773fb6410 Support NTFS reparse points.
* grub-core/fs/ntfs.c (list_file): Set symlink type when appropriate.
	(symlink_descriptor): New struct.
	(grub_ntfs_read_symlink): New function.
	(grub_ntfs_iterate_dir): Use grub_ntfs_read_symlink.
	(grub_ntfs_open): Likewise.
2011-10-27 03:04:27 +02:00
Vladimir 'phcoder' Serbinenko
91c3fdde0d * include/grub/ntfs.h: Add GRUB_NTFS_ prefix. All users updated. 2011-10-27 02:59:45 +02:00
Vladimir 'phcoder' Serbinenko
e9cc6b7b0e * grub-core/fs/ntfs.c (grub_ntfs_uuid): Fix a memory leak. 2011-10-26 00:29:46 +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
0e5507c411 mtime support for ntfs 2010-12-12 01:00:33 +01:00
Vladimir 'phcoder' Serbinenko
34706ddc06 * grub-core/fs/ntfs.c (grub_ntfs_uuid): Make uppercase. 2010-11-06 21:54:24 +01:00
BVK Chaitanya
8c41176882 automake commit without merge history 2010-05-06 11:34:04 +05:30
Renamed from fs/ntfs.c (Browse further)