Commit Graph

125 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
Andrei Borzenkov 4bd4a88725 i386, x86_64, ppc: fix switch fallthrough cases with GCC7
In util/getroot and efidisk slightly modify exitsing comment to mostly
retain it but still make GCC7 compliant with respect to fall through
annotation.

In grub-core/lib/xzembed/xz_dec_lzma2.c it adds same comments as
upstream.

In grub-core/tests/setjmp_tets.c declare functions as "noreturn" to
suppress GCC7 warning.

In grub-core/gnulib/regexec.c use new __attribute__, because existing
annotation is not recognized by GCC7 parser (which requires that comment
immediately precedes case statement).

Otherwise add FALLTHROUGH comment.

Closes: 50598
2017-04-04 19:23:55 +03:00
Andrei Borzenkov dc27d254f2 util/getroot: delete dead code
is_part cannot be non-zero at this point.

Found by: Coveruty scan.
CID: 73838
2016-01-09 20:54:54 +03:00
Vladimir Serbinenko 27d1a67f8a Fix canonicalize_file_name clash.
canonicalize_file_name clashed with gnulib function. Additionally
it was declared in 2 places: emu/misc.h and util/misc.h. Added
grub_ prefix and removed second declaration.
2015-03-04 01:00:19 +01:00
Vladimir Serbinenko 9ee5ae1fae Document intentional fallthroughs.
Found by: Coverity scan.
2015-01-27 17:17:58 +01:00
Vladimir Serbinenko 866f469683 util/getroot: Add missing grub_disk_close.
Found by: Coverity scan.
2015-01-26 09:54:14 +01:00
Vladimir Serbinenko e88f0420b9 Make grub_util_devmapper_part_to_disk and grub_util_find_partition_start
follow the same algorithm to avoid method mismatch. Don't assume
	DMRAID- UUID to mean full disk but instead check that mapping is linear.
2013-12-24 14:16:57 +01:00
Colin Watson 3bc1b2daab Fix various build problems on GNU/Hurd.
* grub-core/osdep/unix/getroot.c (strip_extra_slashes): Move inside
!defined (__GNU__).
(xgetcwd): Likewise.
* include/grub/emu/hostdisk.h (grub_util_hurd_get_disk_info)
[__GNU__]: Add prototype.
* util/getroot.c (grub_util_biosdisk_get_grub_dev) [__GNU__]: Format
long int using %ld rather than %d.
2013-12-20 14:02:27 +00:00
Vladimir Serbinenko 18e76955be Use %I64 and not %ll when using OS printf if compiling for windows. 2013-12-17 16:04:47 +01:00
Colin Watson 1326b9ae2a * util/getroot.c (grub_util_biosdisk_get_grub_dev) [__GNU__]: Remove
unused variables.
2013-11-14 15:08:37 +00:00
Vladimir Serbinenko 66acd9d64c * util/getroot.c (grub_util_biosdisk_get_grub_dev) [__APPLE__]:
Add missing semicolon.
2013-11-11 22:49:52 +01:00
Vladimir 'phcoder' Serbinenko cd78a56fb2 Move stat () and device mode checking into OS-dependent files as
long as performance doesn't suffer.
2013-10-19 16:29:20 +02:00
Vladimir 'phcoder' Serbinenko 3530bc9d90 * util/getroot.c (make_device_name): Remove dos_part and bsd_part as
it's mostly unused. Move vestiges to the callers.
2013-10-10 10:21:07 +02:00
Vladimir 'phcoder' Serbinenko acbbe5cbad * include/grub/util/lvm.h: Removed. 2013-10-08 21:01:09 +02:00
Vladimir 'phcoder' Serbinenko bab7b1ebeb * include/grub/emu/hostdisk.h (GRUB_FD_STAT_IS_FUNTIONAL): New define.
Migrate all explicit defines to this new one.
2013-09-24 19:17:24 +02:00
Vladimir 'phcoder' Serbinenko e8fd80bc3d * util/getroot.c (grub_util_biosdisk_is_present): Don't do stat on
platforms on which it doesn't work.
2013-09-24 18:58:33 +02:00
Vladimir 'phcoder' Serbinenko 5177ba1400 * util/getroot.c (grub_util_check_block_device): Move to ...
* util/getroot_unix.c (grub_util_check_block_device): ... here.
	* util/getroot.c (grub_util_check_char_device): Move to ...
	* util/getroot_unix.c (grub_util_check_char_device): ... here.
2013-09-24 18:55:10 +02:00
Vladimir 'phcoder' Serbinenko 3f7d9c8280 * util/getroot.c (grub_util_biosdisk_get_grub_dev): Do not assume
that floppies are unpartitioned.
2013-09-23 12:19:49 +02:00
Vladimir 'phcoder' Serbinenko bca8873a0c * util/getroot_unix.c [__MINGW32__ || __CYGWIN__]:
Define dummy grub_util_pull_lvm_by_command to decrease number of #if's.
2013-09-23 12:06:00 +02:00
Vladimir 'phcoder' Serbinenko 7e518ca84f Use Winapi on both cygwin and mingw32 to share more code between both. 2013-09-23 11:21:09 +02:00
Vladimir 'phcoder' Serbinenko 3ff4063dd3 * grub-core/kern/emu/hostdisk.c: Disentagle into a series of OS-specific
files rather than one file with loads of #if's.
	* util/getroot.c: Likewise.
2013-09-22 07:36:17 +02:00
Vladimir 'phcoder' Serbinenko 63653cfdae * grub-core/disk/diskfilter.c: Handle non-md UUIDs.
* grub-core/disk/lvm.c: Add LVM UUIDs.
	* util/getroot.c: Use LVM UUIDs whenever possible.
2013-09-20 20:37:03 +02:00
Vladimir 'phcoder' Serbinenko 53c6b7d658 * util/getroot.c (grub_util_open_dm): Check major rather than the name
to determine if device is handled by devmapper.
	(convert_system_partition_to_system_disk): Likewise.
	(get_dm_uuid): Don't check explicitly if device is mapped, it's
	already done in grub_util_open_dm.
2013-09-19 09:46:06 +02:00
Vladimir 'phcoder' Serbinenko 386701a8fe Handle the case of partitioned LVM properly.
* grub-core/kern/emu/hostdisk.c (grub_util_get_dm_node_linear_info):
	Stop on meeting LVM, mpath or DMRAID.
	(grub_hostdisk_os_dev_to_grub_drive): Canonicalize os device.
	(read_device_map): Likewise.
	* util/getroot.c (convert_system_partition_to_system_disk): Assume that
	device is full disk rather than erroring out on LVM and similar cases.
2013-09-19 08:48:54 +02:00
Vladimir 'phcoder' Serbinenko 5dd5e64b71 * util/getroot.c (grub_find_device): Use cygwin_conv_path ratherthan
removed in current versions cygwin_conv_*.
2013-08-23 08:51:21 +02:00
Vladimir 'phcoder' Serbinenko 43ffba7c65 * util/getroot.c: Include sys/wait.h only when we need waitpid. 2013-08-22 16:28:10 +02:00
Ilya Bakulin 0031b22993 * grub-core/kern/emu/hostdisk.c: Add conditionals for OpenBSD.
* util/getroot.c: Likewise.
2013-08-21 21:05:01 +02:00
Andrey Borzenkov 5e7d94641b * util/getroot.c (grub_util_is_imsm): Fix descriptor and
memory leak.
2013-08-14 20:47:09 +04:00
Andrey Borzenkov dea55e2a95 * util/getroot.c (pull_lvm_by_command): add --separator option
to vgs call to disable padding of output to 10 characters.
2013-08-14 20:40:39 +04:00
Colin Watson 36e87d25e1 * util/getroot.c (grub_util_biosdisk_get_grub_dev): Zero out
grub_errno in the case where we handle GRUB_ERR_UNKNOWN_DEVICE by
falling back to the partition device, otherwise a later call to this
function may fail spuriously.
Reported by Axel Beckert.  Fixes Debian bug #708614.
2013-08-13 17:48:56 +02:00
Vladimir 'phcoder' Serbinenko 63314aa43c * util/getroot.c (exec_pipe): Put proper #if's so that its users don't
compile when not needed.
2013-04-26 23:41:13 +02:00
Vladimir 'phcoder' Serbinenko 25fc51a879 Fix DMRAID partition handling. 2013-04-15 08:37:13 +02:00
Vladimir 'phcoder' Serbinenko ba44ca6d1a Replace stpcpy with grub_stpcpy in tools. 2013-04-12 22:37:59 +02:00
Vladimir 'phcoder' Serbinenko 49818a594a Fix missing PVs if they don't contain "interesting" LV. Closes #38677.
Fix few warining messages and leaks while on it.
2013-04-11 00:08:27 +02:00
Colin Watson 25239370fd Remove nested functions from device iterators.
* include/grub/arc/arc.h (grub_arc_iterate_devs_hook_t): New type.
(grub_arc_iterate_devs): Add hook_data argument.
* include/grub/ata.h (grub_ata_dev_iterate_hook_t): New type.
(struct grub_ata_dev.iterate): Add hook_data argument.
* include/grub/device.h (grub_device_iterate_hook_t): New type.
(grub_device_iterate): Add hook_data argument.
* include/grub/disk.h (grub_disk_dev_iterate_hook_t): New type.
(struct grub_disk_dev.iterate): Add hook_data argument.
(grub_disk_dev_iterate): Likewise.
* include/grub/gpt_partition.h (grub_gpt_partition_map_iterate):
Likewise.
* include/grub/msdos_partition.h (grub_partition_msdos_iterate):
Likewise.
* include/grub/partition.h (grub_partition_iterate_hook_t): New
type.
(struct grub_partition_map.iterate): Add hook_data argument.
(grub_partition_iterate): Likewise.
* include/grub/scsi.h (grub_scsi_dev_iterate_hook_t): New type.
(struct grub_scsi_dev.iterate): Add hook_data argument.

Update all callers.
2013-01-20 15:52:15 +00:00
Vladimir 'phcoder' Serbinenko 22099030ad * grub-core/kern/emu/hostdisk.c (read_device_map): Explicitly
delimit path in strings using quotes.
	* util/getroot.c (grub_guess_root_devices): Likewise.
	(grub_make_system_path_relative_to_its_root): Likewise.
	* util/grub-probe.c (probe): Likewise.
	* util/ieee1275/ofpath.c (find_obppath): Likewise.
	(xrealpath): Likewise.
2013-01-13 22:45:16 +01:00
Vladimir 'phcoder' Serbinenko 258f43b7d7 * util/getroot.c (convert_system_partition_to_system_disk): Support
nbd disks.
2012-12-10 11:12:38 +01:00
Colin Watson 794c8c3375 Fix grub-emu build on FreeBSD.
* Makefile.util.def (grub-mount): Add LIBGEOM to ldadd.
* grub-core/net/drivers/emu/emunet.c: Only include Linux-specific
headers on Linux.
(GRUB_MOD_INIT): Return immediately on non-Linux platforms; this
implementation is currently Linux-specific.
* util/getroot.c (exec_pipe): Define only on Linux or when either
libzfs or libnvpair is unavailable.
(find_root_devices_from_poolname): Remove unused path variable.
2012-09-22 21:19:58 +01:00
Vladimir 'phcoder' Serbinenko 592fd0e4d6 * grub-core/disk/diskfilter.c (free_array) [GRUB_UTIL]: Fix memory leak.
* util/getroot.c (grub_find_device): Likewise.
	(get_mdadm_uuid): Likewise.
	(grub_util_is_imsm): Likewise.
	(grub_util_pull_device): Likewise.
	* util/grub-probe.c (probe): Likewise.
2012-09-11 07:53:26 +02:00
Vladimir 'phcoder' Serbinenko d1718e7d2b * util/getroot.c (grub_find_root_devices_from_mountinfo): Handle btrfs
subvolumes.
2012-06-22 22:11:23 +02:00
Vladimir 'phcoder' Serbinenko 29a049c98a * util/getroot.c (convert_system_partition_to_system_disk) [__APPLE__]:
Set is_part appropriately.
	(grub_util_biosdisk_get_grub_dev): Use is_part rather than comparing
	names. Canonicalize partition without full disk.
2012-06-14 19:16:30 +02:00
Vladimir 'phcoder' Serbinenko 558d3a6023 * util/getroot.c (grub_util_get_dm_node_linear_info): Moved from here...
* grub-core/kern/emu/hostdisk.c (grub_util_get_dm_node_linear_info):
	to here. New return value start. All users updated.
	Recursively scan linear mappings.
	* include/grub/emu/hostdisk.h (grub_util_get_dm_node_linear_info): New
	proto.
	* grub-core/kern/emu/hostdisk.c (grub_hostdisk_find_partition_start):
	Use grub_util_get_dm_node_linear_info.
	* util/getroot.c (convert_system_partition_to_system_disk): Use
	grub_util_info rather than grub_dprintf.
	(grub_util_biosdisk_get_grub_dev): Add a new grub_util_info.
2012-06-07 14:24:48 +02:00
Vladimir 'phcoder' Serbinenko de89d33847 * util/getroot.c (grub_guess_root_devices): Don't canonicalise
/dev/root and /dev/dm-*.
2012-06-02 14:36:27 +02:00
Vladimir 'phcoder' Serbinenko 037f6d9060 * util/getroot.c (grub_util_biosdisk_get_grub_dev) [__APPLE__]:
Implement Apple flavour.
	(convert_system_partition_to_system_disk) [__APPLE__]: Likewise.
2012-05-28 17:43:12 +02:00
Samuel Thibault 1796965f6c * util/getroot.c (find_hurd_root_device): Try to make error message
and comments to translators clearer.
2012-05-04 02:26:39 +02:00
Samuel Thibault e5e4ca486c Handle hurd userspace partitions.
* util/getroot.c (find_hurd_root_device): New function.
	(grub_guess_root_devices): Use find_hurd_root_device on Hurd.
2012-05-03 23:41:46 +02:00
Vladimir 'phcoder' Serbinenko 56bb5dd518 * util/getroot.c (convert_system_partition_to_system_disk); Add etherd
names.
	Reported by: Bastian Blank.
2012-05-03 22:59:16 +02:00
Vladimir 'phcoder' Serbinenko bcb288ed17 * util/getroot.c (find_root_devices_from_poolname): Handle spaces in the
name.
2012-05-02 09:56:56 +02:00
root fe4824e998 Fix hurd build.
* util/getroot.c [__GNU__] (strip_extra_slashes, xgetcwd, exec_pipe,
find_root_devices_from_poolname, find_root_devices_from_libzfs,
grub_find_device): Do not define.
2012-04-22 19:02:55 +00:00
Vladimir 'phcoder' Serbinenko 9a06490c07 Fix kfreebsd compile and behaviour.
* grub-core/kern/emu/hostdisk.c (grub_util_follow_gpart_up): Fix
	format-security.
	* util/getroot.c: Fix wait.h include.
	(grub_guess_root_devices): Error if grub_find_device fails.
	(grub_util_get_geom_abstraction): Fix shadowing and format-security.
	(grub_util_get_dev_abstraction): Likewise.
	(grub_util_pull_device): Likewise.
	(grub_util_get_grub_dev): Likewise.
	* util/lvm.c (grub_util_lvm_isvolume): Likewise.
2012-04-21 16:49:56 +02:00