Commit graph

48 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
ca0a4f689a verifiers: File type for fine-grained signature-verification controlling
Let's provide file type info to the I/O layer. This way verifiers
framework and its users will be able to differentiate files and verify
only required ones.

This is preparatory patch.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
2018-11-09 13:25:31 +01:00
Vladimir Serbinenko
641bb15fa4 legacy_initrd: Strip any additional arguments to initrd. 2017-02-27 00:43:54 +00:00
Andrei Borzenkov
eefa3239c2 legacycfg: fix memory leaks and add NULL check
Memory leaks found by Coverity scan.
CID: 96642, 96645
2016-01-16 20:34:02 +03:00
Vladimir Serbinenko
f579f097bb commands/legacycfg: Fix resource leaks. 2015-01-24 21:06:23 +01:00
Vladimir Serbinenko
8063ce197f Replace few instances of memcmp/memcpy in the code that should be grub_memcmp/grub_memcpy. 2014-04-04 07:58:42 +02:00
Vladimir Serbinenko
8ff35d0a1b * grub-core/commands/legacycfg.c: Use 32-bit Linux protocol on non-BIOS. 2013-12-18 05:21:06 +01:00
Vladimir Serbinenko
da93d6753b * grub-core/commands/legacycfg.c (grub_legacy_check_md5_password): Plug
memory leak.
2013-11-18 02:37:46 +01:00
Vladimir Serbinenko
15decd26cc * grub-core/tests/legacy_password_test.c: New test.
* grub-core/commands/legacycfg.c: Remove variable length arrays.
2013-11-12 02:38:33 +01:00
Vladimir Serbinenko
ec0ebb3fc2 Remove vestiges of -Wunsafe-loop-optimisations.
* conf/Makefile.common (CFLAGS_GNULIB): Remove
	-Wno-unsafe-loop-optimisations.
	* grub-core/commands/legacycfg.c: Remove -Wunsafe-loop-optimisations
	pragma.
	* grub-core/io/gzio.c: Likewise.
	* grub-core/script/parser.y: Likewise.
	* grub-core/script/yylex.l: Likewise.
	* util/grub-mkfont.c: Likewise.
2013-11-07 02:25:31 +01:00
Vladimir Serbinenko
c7f34744c6 * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel): Fix
BIOS disk check.
2013-11-07 00:46:44 +01:00
Colin Watson
09fd6d8293 Remove nested functions from script reading and parsing.
* grub-core/kern/parser.c (grub_parser_split_cmdline): Add
getline_data argument, passed to getline.
* grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add
getline_data argument, passed to grub_parser_split_cmdline.
* grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass
lexerstate->getline_data to lexerstate->getline.
(grub_script_lexer_init): Add getline_data argument, saved in
lexerstate->getline_data.
* grub-core/script/main.c (grub_normal_parse_line): Add getline_data
argument, passed to grub_script_parse.
* grub-core/script/script.c (grub_script_parse): Add getline_data
argument, passed to grub_script_lexer_init.
* include/grub/parser.h (grub_parser_split_cmdline): Update
prototype.  Update all callers to pass appropriate getline data.
(struct grub_parser.parse_line): Likewise.
(grub_rescue_parse_line): Likewise.
* include/grub/reader.h (grub_reader_getline_t): Add void *
argument.
* include/grub/script_sh.h (struct grub_lexer_param): Add
getline_data member.
(grub_script_parse): Update prototype.  Update all callers to pass
appropriate getline data.
(grub_script_lexer_init): Likewise.
(grub_normal_parse_line): Likewise.

* grub-core/commands/legacycfg.c (legacy_file_getline): Add unused
data argument.
* grub-core/kern/parser.c (grub_parser_execute: getline): Make
static instead of nested.  Rename to ...
(grub_parser_execute_getline): ... this.
* grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused
data argument.
* grub-core/normal/main.c (read_config_file: getline): Make static
instead of nested.  Rename to ...
(read_config_file_getline): ... this.
(grub_normal_read_line): Add unused data argument.
* grub-core/script/execute.c (grub_script_execute_sourcecode:
getline): Make static instead of nested.  Rename to ...
(grub_script_execute_sourcecode_getline): ... this.
* util/grub-script-check.c (main: get_config_line): Make static
instead of nested.
2013-01-15 12:03:25 +00:00
Colin Watson
5c67ea6cd9 Remove several trivially-unnecessary uses of nested functions.
* grub-core/commands/i386/pc/sendkey.c
(grub_cmd_sendkey: find_key_code, find_ascii_code): Make static
instead of nested.
* grub-core/commands/legacycfg.c (legacy_file: getline): Likewise.
Rename to ...
(legacy_file_getline): ... this.
* grub-core/commands/loadenv.c (grub_cmd_load_env: set_var):
Likewise.
* grub-core/kern/corecmd.c (grub_core_cmd_set: print_env): Likewise.
* grub-core/kern/fs.c (grub_fs_probe: dummy_func): Likewise.  Rename
to ...
(probe_dummy_iter): ... this.
* grub-core/kern/i386/coreboot/mmap.c
(grub_linuxbios_table_iterate: check_signature): Likewise.
* grub-core/kern/parser.c (grub_parser_split_cmdline:
check_varstate): Likewise.  Mark inline.
* grub-core/lib/arg.c (find_short: fnd_short): Likewise.  Pass
an additional parameter.
(find_long: fnd_long): Likewise.  Pass two additional parameters.
* grub-core/lib/crc.c (init_crc32c_table: reflect): Likewise.
* grub-core/lib/crc64.c (init_crc64_table: reflect): Likewise.
* grub-core/lib/ieee1275/cmos.c (grub_cmos_find_port: hook):
Likewise.  Rename to ...
(grub_cmos_find_port_iter): ... this.
* grub-core/lib/ieee1275/datetime.c (find_rtc: hook): Likewise.
Rename to ...
(find_rtc_iter): ... this.

* grub-core/normal/menu_entry.c (run): Fold nested editor_getsource
function directly into the function body, since it is only called
once.
2012-12-31 17:31:38 +00:00
Vladimir 'phcoder' Serbinenko
dc478aeae5 * grub-core/commands/legacycfg.c (legacy_file): Default to restricted
entries.
	* grub-core/commands/menuentry.c (grub_cmd_menuentry): Likewise.
	* docs/grub.texi: Update menuentry description.
2012-05-02 10:26:09 +02:00
Vladimir 'phcoder' Serbinenko
bb51c6c647 * grub-core/commands/acpi.c: Add TRANSLATORS comments.
* grub-core/commands/gptsync.c: Likewise.
	* grub-core/commands/hashsum.c: Likewise.
	* grub-core/commands/i386/pc/sendkey.c: Likewise.
	* grub-core/commands/legacycfg.c: Likewise.
	* grub-core/io/gzio.c: Likewise.
	* grub-core/net/net.c: Likewise.
	* grub-core/term/gfxterm.c: Likewise.
	* grub-core/term/terminfo.c: Likewise.
	* grub-core/tests/test_blockarg.c: Likewise.
	* grub-core/video/video.c: Likewise.
	* util/grub-install.in: Likewise.
	* util/grub-mkfont.c: Likewise.
2012-03-06 14:11:10 +01:00
Vladimir 'phcoder' Serbinenko
d9bef9bc43 Fix menu title instability bug.
* grub-core/commands/menuentry.c (options): New option --id.
	(grub_normal_add_menu_entry): New argument id. All users updated.
	(grub_cmd_menuentry): Handle --id.
	(grub_menu_init): Accept unknown arguments.
	* grub-core/normal/main.c (features): Add feature_menuentry_id and
	feature_menuentry_options.
	* grub-core/normal/menu.c (grub_menu_execute_entry): Use id for
	saved_entry.
	(get_entry_number): Match with id as well.
	* include/grub/menu.h (grub_menu_entry): New member id.
	* util/grub-mkconfig_lib.in (grub_get_device_id): New function.
	* util/grub.d/00_header.in: Define menuentry_id_option.
	* util/grub.d/10_hurd.in: Define id.
	* util/grub.d/10_illumos.in: Likewise.
	* util/grub.d/10_kfreebsd.in: Likewise.
	* util/grub.d/10_linux.in: Likewise.
	* util/grub.d/10_netbsd.in: Likewise.
	* util/grub.d/10_windows.in: Likewise.
	* util/grub.d/20_linux_xen.in: Likewise.
	* util/grub.d/30_os-prober.in: Likewise.
2012-03-04 14:55:13 +01:00
Vladimir 'phcoder' Serbinenko
67093bc0ed Another round of string clarification and adding TRANSLATORS comments. 2012-02-26 17:28:05 +01:00
Vladimir 'phcoder' Serbinenko
4e27343fb0 * conf/Makefile.common (CFLAGS_GNULIB): Add
-Wno-unsafe-loop-optimizations.
	* configure.ac: Remove -Wmissing-declarations and -Wmissing-prototypes
	on tools.
	* grub-core/commands/legacycfg.c: Add pragma to skip
	-Wunsafe-loop-optimizations.
	(check_password_md5_real): Fix loop counter type.
	* grub-core/commands/testload.c (grub_cmd_testload): Fix over the EOF
	reading.
	* grub-core/disk/ldm.c (grub_util_get_ldm): Fix logic error.
	* grub-core/fs/zfs/zfs_sha256.c (zio_checksum_SHA256): Add safety
	loop condition.
	* grub-core/io/gzio.c: Add pragma to skip -Wunsafe-loop-optimizations.
	* grub-core/lib/LzmaEnc.c (GetOptimum): Avoid possible infinite loop.
	* grub-core/net/net.c (grub_net_route_address): Add safety loop
	condition.
	* grub-core/normal/charset.c (bidi_line_wrap): Likewise.
	* grub-core/normal/cmdline.c (grub_set_history): Fix loop types and
	avoid possible infinite loops.
	* grub-core/script/parser.y: Add pragma to skip -Wmissing-declarations
	and -Wunsafe-loop-optimizations.
	* grub-core/script/yylex.l: Likewise.
	* util/grub-mkfont.c: Add pragma to skip -Wunsafe-loop-optimizations.
	(print_glyphs): Avoid infinite loops.
	* util/grub-mkimage.c (compress_kernel_xz): Fix format security.
2012-02-24 12:30:32 +01:00
Vladimir 'phcoder' Serbinenko
d61386e21d Improve string. Gettextize. 2012-02-12 15:25:25 +01:00
Vladimir 'phcoder' Serbinenko
29a3550b61 * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel):
Avoid improper use of strings.
	(grub_cmd_legacy_initrdnounzip): Likewise.
2012-02-10 14:30:19 +01:00
Vladimir 'phcoder' Serbinenko
9c4b5c13e6 Improve gettext support. Stylistic fixes and error handling fixes while
on it.
2012-02-08 19:26:01 +01:00
Vladimir 'phcoder' Serbinenko
b525fd834d Clarify and unify messages.
* grub-core/commands/hashsum.c (options): Unify messages.
	* grub-core/commands/keystatus.c (GRUB_MOD_INIT): Don't mark a
	literal-only message as translatable.
	* grub-core/commands/lsacpi.c (GRUB_MOD_INIT): Likewise.
	* grub-core/loader/ia64/efi/linux.c (GRUB_MOD_INIT): Likewise.
	* grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Add quoting around
	commands.
	* grub-core/commands/menuentry.c (options): Clarify that it's a keyboard
	key, not the key used to unlock. Clarify what it's used for.
	* grub-core/kern/emu/hostdisk.c (read_device_map): Unify error message.
	* grub-core/loader/xnu.c (grub_xnu_load_driver): Remove erroneous colon.
	* grub-core/script/main.c (GRUB_MOD_INIT): Clarify [n] to be [NUM].
	* util/grub-editenv.c (options): Unify "verbose" message.
	* util/grub-fstest.c (read_file): Unify error message.
	(fstest): Add quotes around commands.
	(options): Unify "verbose" message.
	* util/grub-install.in: Add quotes around variable name.
	* util/grub-kbdcomp.in: Unify error message.
	* util/grub-mkfont.c (main): Likewise.
	* util/grub-mkrescue.in: Likewise.
	* util/grub-mklayout.c (options): Unify "verbose" message.
	* util/grub-mkstandalone.in: Unify help and verbose messages.
	* util/grub-mount.c (options): Unify "verbose" message.
	* util/grub-probe.c (options): Likewise.
	* util/grub-script-check.c (options): Likewise.
	* util/grub-setup.c (setup): Unify no-terminator message.
	(options): Use DEVICE and not DEV.
	Unify "verbose" message.
	* util/ieee1275/ofpath.c (xrealpath): Unify error message.
2012-02-05 11:23:47 +01:00
Vladimir 'phcoder' Serbinenko
6e0632e28c * grub-core/commands/acpihalt.c: Gettextized.
* grub-core/commands/cacheinfo.c: Likewise.
	* grub-core/commands/cmp.c: Likewise.
	* grub-core/commands/efi/loadbios.c: Likewise.
	* grub-core/commands/gptsync.c: Likewise.
	* grub-core/commands/ieee1275/suspend.c: Likewise.
	* grub-core/commands/legacycfg.c: Likewise.
	* grub-core/commands/memrw.c: Likewise.
	* grub-core/commands/minicmd.c: Likewise.
	* grub-core/commands/parttool.c: Likewise.
	* grub-core/commands/time.c: Likewise.
	* grub-core/commands/videoinfo.c: Likewise.
	* grub-core/disk/geli.c: Likewise.
	* grub-core/disk/i386/pc/biosdisk.c: Likewise.
	* grub-core/disk/luks.c: Likewise.
	* grub-core/disk/lvm.c: Likewise.
	* grub-core/font/font_cmd.c: Likewise.
	* grub-core/fs/zfs/zfscrypt.c: Likewise.
	* grub-core/fs/zfs/zfsinfo.c: Likewise.
	* grub-core/gfxmenu/view.c: Likewise.
	* grub-core/kern/emu/hostdisk.c: Likewise.
	* grub-core/kern/emu/main.c: Likewise.
	* grub-core/kern/emu/misc.c: Likewise.
	* grub-core/kern/emu/mm.c: Likewise.
	* grub-core/kern/mips/arc/init.c: Likewise.
	* grub-core/kern/mips/loongson/init.c: Likewise.
	* grub-core/kern/partition.c: Likewise.
	* grub-core/lib/i386/halt.c: Likewise.
	* grub-core/lib/mips/arc/reboot.c: Likewise.
	* grub-core/lib/mips/loongson/reboot.c: Likewise.
	* grub-core/loader/i386/pc/chainloader.c: Likewise.
	* grub-core/loader/i386/xnu.c: Likewise.
	* grub-core/loader/multiboot.c: Likewise.
	* grub-core/net/bootp.c: Likewise.
	* grub-core/net/net.c: Likewise.
	* grub-core/normal/term.c: Likewise.
	* grub-core/partmap/bsdlabel.c: Likewise.
	* grub-core/parttool/msdospart.c: Likewise.
	* grub-core/term/gfxterm.c: Likewise.
	* grub-core/term/terminfo.c: Likewise.
	* grub-core/video/i386/pc/vbe.c: Likewise.
	* util/grub-menulst2cfg.c: Likewise.
	* util/grub-mkdevicemap.c: Likewise.
	* util/grub-mklayout.c: Likewise.
	* util/grub-mkrelpath.c: Likewise.
	* util/grub-script-check.c: Likewise.
	* util/ieee1275/grub-ofpathname.c: Likewise.
	* util/resolve.c: Likewise.
2011-11-11 21:44:56 +01:00
Vladimir 'phcoder' Serbinenko
d35d0d3753 Add const keyword to grub_env_get and gettextize week days.
* grub-core/hook/datehook.c (grub_datetime_names): Make const.
	(grub_read_hook_datetime): Return const char *.
	* grub-core/kern/env.c (grub_env_get): Return const char *. All users
	updated.
	* grub-core/normal/datetime.c (grub_weekday_names): Make const.
	Mark for gettext.
	(grub_get_weekday_name): Return const char *. Call gettext.
	* grub-core/script/argv.c (grub_script_argv_append): Receive const
	char * and len as the argument. All users updated.
	(grub_script_argv_split_append): Receive const char *.
	* include/grub/datetime.h (grub_get_weekday_name): Update proto.
	* include/grub/env.h (grub_env_get): Likewise.
	(grub_env_read_hook_t): Return const char *.
	* include/grub/script_sh.h (grub_script_argv_append): Update proto.
	(grub_script_argv_split_append): Likewise.
2011-11-11 20:34:37 +01: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
dcb883b162 Submenu default support.
* grub-core/normal/menu.c (grub_menu_execute_entry): New parameter
	auto_boot. All users updated.
	Declared static.
	Handle chosen and default with submenus.
	(grub_menu_execute_with_fallback): Declared static.
	Don't notify failure if autobooted. Upper level does it.
	(menuentry_eq): New function.
	(get_entry_number): Use menuentry_eq.
	(show_menu): New parameter "autobooted". All users updated.
	(grub_show_menu): Likewise.
	* include/grub/normal.h (grub_show_menu): Likewise.
	* include/grub/menu.h (grub_menu_execute_entry): Removed.
	(grub_menu_execute_with_fallback): Likewise.
2011-01-10 23:27:58 +01:00
Vladimir 'phcoder' Serbinenko
47a77af5e8 * grub-core/commands/legacycfg.c (legacy_file): Trim the line. 2011-01-10 19:25:00 +01:00
Colin Watson
5b1bdf1231 * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Fix typo in
descriptions of extract_legacy_entries_source and
extract_legacy_entries_configfile.
Reported by: Seung Soo, Ha.
2011-01-04 13:05:19 +00:00
Vladimir 'phcoder' Serbinenko
f18088844f Make legacy_source behave like source.
* grub-core/commands/legacycfg.c (legacy_file): Don't call
	grub_show_menu.
	(grub_cmd_legacy_source): Call grub_show_menu if needed.
2010-11-17 08:41:18 +01:00
Szymon Janc
6bdda8f877 * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel):
Set-but-not-used variable ifdef'ed.
	* grub-core/lib/legacy_parse.c (grub_legacy_parse): Likewise.
	* grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Set-but-not-used
	variable removed.
	* grub-core/disk/lvm.c (grub_lvm_scan_device): Likewise.
	* grub-core/fs/jfs.c (grub_jfs_find_file): Likewise.
	* grub-core/fs/minix.c (grub_minix_dir): Likewise.
	* grub-core/fs/sfs.c (grub_sfs_read_extent): Likewise.
	* grub-core/fs/ufs.c (grub_ufs_dir): Likewise.
	* grub-core/gfxmenu/gui_list.c (grub_gui_list_new): Likewise.
	* grub-core/gfxmenu/view.c (redraw_menu_visit): Likewise.
	* grub-core/gfxmenu/widget-box.c (draw): Likewise.
	* grub-core/lib/relocator.c (malloc_in_range): Likewise.
	* grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): Likewise.
	* grub-core/loader/i386/bsd_pagetable.c (fill_bsd64_pagetable):
	Likewise.
2010-10-16 22:16:52 +02:00
Vladimir 'phcoder' Serbinenko
fc55cc4c27 Support submenus.
* grub-core/commands/menuentry.c (grub_normal_add_menu_entry): New
	parameter submenu. All users updated.
	* grub-core/normal/main.c (free_menu): Rename to ...
	(grub_normal_free_menu): ... this. Made global.
	* grub-core/normal/menu.c (grub_menu_execute_entry): Open new context
	if requested.
	* grub-core/normal/menu_entry.c (screen): New field submenu.
	(make_screen): Set submenu.
	(run): Open new context if requested.
	* include/grub/menu.h (grub_menu_entry): New field submenu.
	* include/grub/normal.h (grub_normal_free_menu): New proto.
2010-09-21 00:47:49 +02:00
Vladimir 'phcoder' Serbinenko
57f20e67a0 Support extraction of legacy entries 2010-09-20 23:10:29 +02:00
Vladimir 'phcoder' Serbinenko
a38b701cbf Rename jail to extractor 2010-09-20 23:01:34 +02:00
Vladimir 'phcoder' Serbinenko
e2830452f0 Support legacy_check_password 2010-09-15 13:51:02 +02:00
Vladimir 'phcoder' Serbinenko
e64334df29 Support mixed inline and suffix commands 2010-09-12 15:50:52 +02:00
Vladimir 'phcoder' Serbinenko
281d690594 Add no-argument version of commands and remove legacy_color 2010-09-12 15:26:38 +02:00
Vladimir 'phcoder' Serbinenko
64ad6157ae Fix bunch of memory problems and implement hdbias 2010-09-12 14:01:02 +02:00
Vladimir 'phcoder' Serbinenko
6c6850ae13 Implement hiddenmenu (not tested) 2010-09-12 02:55:24 +02:00
Vladimir 'phcoder' Serbinenko
237a43b1c1 Support few more legacy commands 2010-09-12 02:30:48 +02:00
Vladimir 'phcoder' Serbinenko
a37376e72a legacy_password implementation 2010-09-12 01:07:41 +02:00
Vladimir 'phcoder' Serbinenko
8bc402fbda Remove obsolete FIXME comments 2010-09-11 22:47:49 +02:00
Vladimir 'phcoder' Serbinenko
bd9603071a Merge mainline into legacy_parser 2010-09-11 22:39:55 +02:00
Vladimir 'phcoder' Serbinenko
9fb175ed9a Implement multiboot filename duplication in legacy parser 2010-09-11 22:18:41 +02:00
Vladimir 'phcoder' Serbinenko
2a87d7d1b6 Remove biglinux FIXME comment. It's a non-issue 2010-08-27 22:34:25 +02:00
Vladimir 'phcoder' Serbinenko
7ddbecf25f implement legacy_color 2010-08-27 22:09:09 +02:00
Vladimir 'phcoder' Serbinenko
8fc6a27147 Implement legacy_kernel and legacy_initrd commands 2010-08-27 21:27:26 +02:00
Vladimir 'phcoder' Serbinenko
fff175c77f Implement grub-menulst2cfg and fix many bugs in legacy_parser 2010-08-27 20:04:49 +02:00
Vladimir 'phcoder' Serbinenko
92eb189b69 Merge mainline into legacy_parser 2010-08-27 19:05:06 +02:00