From 5fb29d2da6c849bdab8005fe435c4549ef746415 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Mar 05 2015 13:20:35 +0000 Subject: import efibootmgr-0.8.0-5.el7 --- diff --git a/.efibootmgr.metadata b/.efibootmgr.metadata index 5988942..9e6b5cf 100644 --- a/.efibootmgr.metadata +++ b/.efibootmgr.metadata @@ -1 +1 @@ -eebdb671638f3a7901690df2a8f647e7f8666ed2 SOURCES/efibootmgr-0.5.4.tar.gz +cb7ff114d22f99ba7e386abd777cb78c28c37575 SOURCES/efibootmgr-0.8.0.tar.bz2 diff --git a/.gitignore b/.gitignore index b570c82..3654103 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -SOURCES/efibootmgr-0.5.4.tar.gz +SOURCES/efibootmgr-0.8.0.tar.bz2 diff --git a/SOURCES/0001-Don-t-error-on-unset-BootOrder-when-we-re-trying-to-.patch b/SOURCES/0001-Don-t-error-on-unset-BootOrder-when-we-re-trying-to-.patch new file mode 100644 index 0000000..a8923f8 --- /dev/null +++ b/SOURCES/0001-Don-t-error-on-unset-BootOrder-when-we-re-trying-to-.patch @@ -0,0 +1,566 @@ +From 91ea62136543582a9d9effd32bcccce12b748114 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 15 Oct 2014 10:35:56 -0400 +Subject: [PATCH] Don't error on unset BootOrder when we're trying to add to or + rm from it. + +Also print some better error messases here and there. + +Signed-off-by: Peter Jones +--- + README | 1 - + src/efibootmgr/efibootmgr.c | 126 +++++++++++++++++++++++++++----------------- + src/lib/efi.c | 95 +++++++++++++++++++-------------- + src/man/man8/efibootmgr.8 | 3 -- + 4 files changed, 131 insertions(+), 94 deletions(-) + +diff --git a/README b/README +index 3bc0a26..edbce4b 100644 +--- a/README ++++ b/README +@@ -29,7 +29,6 @@ usage: efibootmgr [options] + -O | --delete-bootorder delete BootOrder + -p | --part part (defaults to 1) containing loader + -q | --quiet be quiet +- --test filename don't write to NVRAM, write to filename + -t | --timeout seconds Boot manager timeout + -T | --delete-timeout delete Timeout value + -u | --unicode | --UCS-2 pass extra args as UCS-2 (default is ASCII) +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 4d80f87..eb13942 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -33,6 +33,7 @@ + #define _GNU_SOURCE + + #include ++#include + #include + #include + #include +@@ -123,7 +124,7 @@ read_vars(char **namelist, + } + return; + err: +- fprintf(stderr, "efibootmgr: %m\n"); ++ warn("efibootmgr"); + exit(1); + } + +@@ -242,16 +243,20 @@ make_boot_var(list_t *boot_list) + free_number = opts.bootnum; + } + +- if (free_number == -1) ++ if (free_number == -1) { ++ warn("efibootmgr: no available boot variables"); + return NULL; ++ } + + /* Create a new efi_variable_t object + and populate it. + */ + + boot = calloc(1, sizeof(*boot)); +- if (!boot) ++ if (!boot) { ++ warn("efibootmgr"); + return NULL; ++ } + if (make_linux_load_option(&boot->data, &boot->data_size) < 0) + goto err_boot_entry; + if (append_extra_args(&boot->data, &boot->data_size) < 0) +@@ -260,8 +265,10 @@ make_boot_var(list_t *boot_list) + boot->num = free_number; + boot->guid = EFI_GLOBAL_VARIABLE; + rc = asprintf(&boot->name, "Boot%04X", free_number); +- if (rc < 0) ++ if (rc < 0) { ++ warn("efibootmgr"); + goto err_boot_entry; ++ } + boot->attributes = EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS; +@@ -272,8 +279,12 @@ make_boot_var(list_t *boot_list) + list_add_tail(&boot->list, boot_list); + return boot; + err_boot_entry: +- if (boot->name) ++ if (boot->name) { ++ warn("Could not set variable %s", boot->name); + free(boot->name); ++ } else { ++ warn("Could not set variable"); ++ } + if (boot->data) + free(boot->data); + free(boot); +@@ -313,6 +324,15 @@ read_boot_order(efi_variable_t **boot_order) + } + + static int ++set_boot_u16(const char *name, uint16_t num) ++{ ++ return efi_set_variable(EFI_GLOBAL_GUID, name, (uint8_t *)&num, ++ sizeof (num), EFI_VARIABLE_NON_VOLATILE | ++ EFI_VARIABLE_BOOTSERVICE_ACCESS | ++ EFI_VARIABLE_RUNTIME_ACCESS); ++} ++ ++static int + add_to_boot_order(uint16_t num) + { + efi_variable_t *boot_order = NULL; +@@ -321,8 +341,11 @@ add_to_boot_order(uint16_t num) + int rc; + + rc = read_boot_order(&boot_order); +- if (rc < 0) ++ if (rc < 0) { ++ if (errno == ENOENT) ++ rc = set_boot_u16("BootOrder", num); + return rc; ++ } + + /* We've now got an array (in boot_order->data) of the + * boot order. First add our entry, then copy the old array. +@@ -358,8 +381,11 @@ remove_dupes_from_boot_order(void) + int rc; + + rc = read_boot_order(&boot_order); +- if (rc < 0) ++ if (rc < 0) { ++ if (errno == ENOENT) ++ rc = 0; + return rc; ++ } + + old_data = (uint16_t *)(boot_order->data); + /* Start with the same size */ +@@ -409,8 +435,11 @@ remove_from_boot_order(uint16_t num) + int rc; + + rc = read_boot_order(&boot_order); +- if (rc < 0) ++ if (rc < 0) { ++ if (errno == ENOENT) ++ rc = 0; + return rc; ++ } + + /* We've now got an array (in boot_order->data) of the + boot order. Simply copy the array, skipping the +@@ -470,15 +499,6 @@ read_boot_u16(const char *name) + } + + static int +-set_boot_u16(const char *name, uint16_t num) +-{ +- return efi_set_variable(EFI_GLOBAL_GUID, name, (uint8_t *)&num, +- sizeof (num), EFI_VARIABLE_NON_VOLATILE | +- EFI_VARIABLE_BOOTSERVICE_ACCESS | +- EFI_VARIABLE_RUNTIME_ACCESS); +-} +- +-static int + delete_boot_var(uint16_t num) + { + int rc; +@@ -490,13 +510,18 @@ delete_boot_var(uint16_t num) + rc = efi_del_variable(EFI_GLOBAL_GUID, name); + + /* For backwards compatibility, try to delete abcdef entries as well */ +- if (rc < 0 && errno == ENOENT) { +- snprintf(name, sizeof(name), "Boot%04x", num); +- rc = efi_del_variable(EFI_GLOBAL_GUID, name); ++ if (rc < 0) { ++ if (errno == ENOENT) { ++ snprintf(name, sizeof(name), "Boot%04x", num); ++ rc = efi_del_variable(EFI_GLOBAL_GUID, name); ++ } else if (errno == EPERM) { ++ warn("Could not delete Boot%04X", num); ++ return rc; ++ } + } + + if (rc < 0) { +- fprintf(stderr,"\nboot entry: %X not found\n\n",num); ++ warnx("Boot entry %04X not found", num); + return rc; + } + list_for_each_safe(pos, n, &boot_entry_list) { +@@ -512,7 +537,6 @@ delete_boot_var(uint16_t num) + return 0; + } + +- + static void + set_var_nums(list_t *list) + { +@@ -1177,34 +1201,28 @@ main(int argc, char **argv) + if (opts.iface && ( + opts.acpi_hid < 0 || opts.acpi_uid < 0 || + opts.acpi_hid > UINT32_MAX || +- opts.acpi_uid > UINT32_MAX)) { +- fprintf(stderr, "\nYou must specify the ACPI HID and UID when using -i.\n\n"); +- return 1; +- } ++ opts.acpi_uid > UINT32_MAX)) ++ errx(1, "You must specify the ACPI HID and UID when using -i."); + +- if (!efi_variables_supported()) { +- fprintf(stderr, "\nEFI variables are not supported on this system.\n\n"); +- return 1; +- } ++ if (!efi_variables_supported()) ++ errx(2, "EFI variables are not supported on this system."); + + read_boot_var_names(&boot_names); + read_vars(boot_names, &boot_entry_list); + set_var_nums(&boot_entry_list); + + if (opts.delete_boot) { +- if (opts.bootnum == -1) { +- fprintf(stderr, "\nYou must specify a boot entry to delete (see the -b option).\n\n"); +- return 1; +- } ++ if (opts.bootnum == -1) ++ errx(3, "You must specify a boot entry to delete " ++ "(see the -b option)."); + else + ret = delete_boot_var(opts.bootnum); + } + + if (opts.active >= 0) { +- if (opts.bootnum == -1) { +- fprintf(stderr, "\nYou must specify a boot entry to activate (see the -b option).\n\n"); +- return 1; +- } ++ if (opts.bootnum == -1) ++ errx(4, "You must specify a boot entry to activate " ++ "(see the -b option"); + else + ret=set_active_state(); + } +@@ -1212,47 +1230,57 @@ main(int argc, char **argv) + if (opts.create) { + warn_duplicate_name(&boot_entry_list); + new_boot = make_boot_var(&boot_entry_list); +- if (!new_boot) { +- fprintf(stderr, "\nCould not prepare boot variable: %m\n\n"); +- return 1; +- } ++ if (!new_boot) ++ err(5, "Could not prepare boot variable"); + + /* Put this boot var in the right BootOrder */ + if (new_boot) + ret=add_to_boot_order(new_boot->num); ++ if (ret) ++ err(6, "Could not add entry to BootOrder"); + } + + if (opts.delete_bootorder) { + ret = efi_del_variable(EFI_GLOBAL_GUID, "BootOrder"); ++ err(7, "Could not remove entry from BootOrder"); + } + + if (opts.bootorder) { + ret = set_boot_order(opts.keep_old_entries); ++ if (ret) ++ err(8, "Could not set BootOrder"); + } + + if (opts.deduplicate) { + ret = remove_dupes_from_boot_order(); ++ if (ret) ++ err(9, "Could not set BootOrder"); + } + + if (opts.delete_bootnext) { + ret = efi_del_variable(EFI_GLOBAL_GUID, "BootNext"); ++ if (ret) ++ err(10, "Could not set BootNext"); + } + + if (opts.delete_timeout) { + ret = efi_del_variable(EFI_GLOBAL_GUID, "Timeout"); ++ if (ret) ++ err(11, "Could not delete Timeout"); + } + + if (opts.bootnext >= 0) { +- if (!is_current_boot_entry(opts.bootnext & 0xFFFF)){ +- fprintf (stderr,"\n\nboot entry %X does not exist\n\n", +- opts.bootnext); +- return 1; +- } +- ret=set_boot_u16("BootNext", opts.bootnext & 0xFFFF); ++ if (!is_current_boot_entry(opts.bootnext & 0xFFFF)) ++ errx(12, "Boot entry %X does not exist", opts.bootnext); ++ ret = set_boot_u16("BootNext", opts.bootnext & 0xFFFF); ++ if (ret) ++ err(13, "Could not set BootNext"); + } + + if (opts.set_timeout) { +- ret=set_boot_u16("Timeout", opts.timeout); ++ ret = set_boot_u16("Timeout", opts.timeout); ++ if (ret) ++ err(14, "Could not set Timeout"); + } + + if (!opts.quiet && ret == 0) { +diff --git a/src/lib/efi.c b/src/lib/efi.c +index 7cdc884..d19c00d 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -19,6 +19,7 @@ + */ + + #include ++#include + #include + #include + #include +@@ -502,7 +503,6 @@ static ssize_t + make_disk_load_option(char *disk, uint8_t *buf, size_t size) + { + int disk_fd=0; +- char buffer[80]; + char signature[16]; + int rc, edd_version=0; + uint8_t mbr_type=0, signature_type=0; +@@ -514,11 +514,8 @@ make_disk_load_option(char *disk, uint8_t *buf, size_t size) + memset(signature, 0, sizeof(signature)); + + disk_fd = open(opts.disk, O_RDWR); +- if (disk_fd == -1) { +- sprintf(buffer, "Could not open disk %s", opts.disk); +- perror(buffer); +- return -1; +- } ++ if (disk_fd == -1) ++ err(5, "Could not open disk %s", opts.disk); + + if (opts.edd_version) { + edd_version = get_edd_version(); +@@ -539,12 +536,10 @@ make_disk_load_option(char *disk, uint8_t *buf, size_t size) + &part_start, &part_size, signature, + &mbr_type, &signature_type); + close(disk_fd); +- if (rc) { +- fprintf(stderr, "Error: no partition information on disk %s.\n" +- " Cowardly refusing to create a boot option.\n", ++ if (rc) ++ errx(5, "No partition information on disk %s.\n" ++ "Cowardly refusing to create a boot option.\n", + opts.disk); +- return -1; +- } + + needed = make_harddrive_device_path(opts.part, part_start, part_size, + (uint8_t *)signature, mbr_type, +@@ -724,10 +719,13 @@ make_linux_load_option(uint8_t **data, size_t *data_size) + uint8_t *buf; + ssize_t needed; + off_t buf_offset = 0, desc_offset; ++ int rc; + + load_option = calloc(1, sizeof (*load_option)); +- if (load_option == NULL) ++ if (load_option == NULL) { ++ fprintf(stderr, "efibootmgr: %m\n"); + return -1; ++ } + buf = (uint8_t *)load_option; + buf_offset = 0; + +@@ -755,21 +753,33 @@ make_linux_load_option(uint8_t **data, size_t *data_size) + if (opts.iface) { + needed = make_net_load_option(opts.iface, NULL, 0); + if (needed < 0) { ++ fprintf(stderr, "efibootmgr: could not create load option: %m\n"); + free(buf); + return needed; + } + buf = extend(load_option, load_option_size, needed); +- make_net_load_option(opts.iface, buf + buf_offset, needed); ++ rc = make_net_load_option(opts.iface, buf + buf_offset, needed); + buf_offset += needed; ++ if (rc < 0) { ++ fprintf(stderr, "efibootmgr: could not create load option: %m\n"); ++ free(buf); ++ return rc; ++ } + } else { + needed = make_disk_load_option(opts.iface, NULL, 0); + if (needed < 0) { ++ fprintf(stderr, "efibootmgr: could not create load option: %m\n"); + free(buf); + return needed; + } + buf = extend(load_option, load_option_size, needed); +- make_disk_load_option(opts.iface, buf + buf_offset, needed); ++ rc = make_disk_load_option(opts.iface, buf + buf_offset, needed); + buf_offset += needed; ++ if (rc < 0) { ++ fprintf(stderr, "efibootmgr: could not create load option: %m\n"); ++ free(buf); ++ return rc; ++ } + } + + load_option->file_path_list_length = buf_offset - desc_offset; +@@ -792,25 +802,25 @@ append_extra_args_ascii(uint8_t **data, size_t *data_size) + int i; + unsigned long usedchars=0; + +- if (!data || *data) ++ if (!data || *data) { ++ errno = EINVAL; + return -1; ++ } + + for (i=opts.optind; i < opts.argc; i++) { +- int l = strlen(opts.argv[i]) + 1; ++ int l = strlen(opts.argv[i]); + int space = (i < opts.argc - 1) ? 1: 0; +- uint8_t *tmp = realloc(new_data, (usedchars + l + space)); ++ uint8_t *tmp = realloc(new_data, (usedchars + l + space + 1)); + if (tmp == NULL) + return -1; + new_data = tmp; + p = (char *)new_data + usedchars; + strcpy(p, opts.argv[i]); + usedchars += l; +- p += l; + /* Put a space between args */ + if (space) +- p[usedchars++] = ' '; +- else +- p[usedchars] = '\0'; ++ new_data[usedchars++] = ' '; ++ new_data[usedchars] = '\0'; + } + + if (!new_data) +@@ -829,8 +839,10 @@ append_extra_args_unicode(uint8_t **data, size_t *data_size) + int i; + unsigned long usedchars=0; + +- if (!data || *data) ++ if (!data || *data) { ++ errno = EINVAL; + return -1; ++ } + + for (i = opts.optind; i < opts.argc; i++) { + int l = strlen(opts.argv[i]) + 1; +@@ -871,37 +883,31 @@ append_extra_args_file(uint8_t **data, size_t *data_size) + size_t maxchars = 0; + char *buffer; + +- if (!data) { +- fprintf(stderr, "internal error\n"); +- exit(1); ++ if (!data || *data) { ++ errno = EINVAL; ++ return -1; + } + + if (file && strncmp(file, "-", 1)) + fd = open(file, O_RDONLY); + +- if (fd == -1) { +- perror("Failed to open extra arguments file"); +- exit(1); +- } ++ if (fd < 0) ++ return -1; + + buffer = malloc(maxchars); + do { + if (maxchars - appended == 0) { + maxchars += 1024; + char *tmp = realloc(buffer, maxchars); +- if (tmp == NULL) { +- perror("Error reading extra arguments file"); +- exit(1); +- } ++ if (tmp == NULL) ++ return -1; + buffer = tmp; + } + num_read = read(fd, buffer + appended, maxchars - appended); +- if (num_read < 0) { +- perror("Error reading extra arguments file"); +- exit(1); +- } else if (num_read > 0) { ++ if (num_read < 0) ++ return -1; ++ else if (num_read > 0) + appended += num_read; +- } + } while (num_read > 0); + + if (fd != STDIN_FILENO) +@@ -935,14 +941,18 @@ append_extra_args(uint8_t **data, size_t *data_size) + + if (opts.extra_opts_file) { + ret = append_extra_args_file(&new_data, &new_data_size); +- if (ret < 0) ++ if (ret < 0) { ++ fprintf(stderr, "efibootmgr: append_extra_args: %m\n"); + return -1; ++ } + } + if (new_data_size) { + ret = add_new_data(data, data_size, new_data, new_data_size); + free(new_data); +- if (ret < 0) ++ if (ret < 0) { ++ fprintf(stderr, "efibootmgr: append_extra_args: %m\n"); + return -1; ++ } + new_data = NULL; + new_data_size = 0; + } +@@ -952,6 +962,7 @@ append_extra_args(uint8_t **data, size_t *data_size) + else + ret = append_extra_args_ascii(&new_data, &new_data_size); + if (ret < 0) { ++ fprintf(stderr, "efibootmgr: append_extra_args: %m\n"); + if (new_data) /* this can't happen, but covscan believes */ + free(new_data); + return -1; +@@ -960,8 +971,10 @@ append_extra_args(uint8_t **data, size_t *data_size) + ret = add_new_data(data, data_size, new_data, new_data_size); + free(new_data); + new_data = NULL; +- if (ret < 0) ++ if (ret < 0) { ++ fprintf(stderr, "efibootmgr: append_extra_args: %m\n"); + return -1; ++ } + new_data_size = 0; + } + +diff --git a/src/man/man8/efibootmgr.8 b/src/man/man8/efibootmgr.8 +index 96071d7..423bc16 100644 +--- a/src/man/man8/efibootmgr.8 ++++ b/src/man/man8/efibootmgr.8 +@@ -93,9 +93,6 @@ Partition number containing the bootloader (defaults to 1) + \fB-q | --quiet\fR + Quiet mode - supresses output. + .TP +-\fB--test \fIfilename\fB\fR +-Don't write to NVRAM, write to \fIfilename\fR\&. +-.TP + \fB-t | --timeout \fIseconds\fB\fR + Boot Manager timeout, in \fIseconds\fR\&. + .TP +-- +1.9.3 + diff --git a/SOURCES/0001-Fix-a-bad-allocation-size.patch b/SOURCES/0001-Fix-a-bad-allocation-size.patch new file mode 100644 index 0000000..3a23146 --- /dev/null +++ b/SOURCES/0001-Fix-a-bad-allocation-size.patch @@ -0,0 +1,28 @@ +From ff8b967fed11558c448a3554dffd6c2b8fa32cef Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:27:02 -0400 +Subject: [PATCH 01/18] Fix a bad allocation size. + +Covscan found this. + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index 133b8bb..6b25dfe 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -717,7 +717,7 @@ make_linux_load_option(uint8_t **data, size_t *data_size) + size_t needed; + off_t buf_offset = 0, desc_offset; + +- load_option = calloc(1, sizeof (load_option)); ++ load_option = calloc(1, sizeof (*load_option)); + if (load_option == NULL) + return -1; + buf = (uint8_t *)load_option; +-- +1.9.3 + diff --git a/SOURCES/0001-Fix-buffer-overflow-when-remove_from_boot_order-remo.patch b/SOURCES/0001-Fix-buffer-overflow-when-remove_from_boot_order-remo.patch new file mode 100644 index 0000000..ca4c196 --- /dev/null +++ b/SOURCES/0001-Fix-buffer-overflow-when-remove_from_boot_order-remo.patch @@ -0,0 +1,95 @@ +From 50ae3bd11b51f8e6cd86d4b4f2c8322a7036d095 Mon Sep 17 00:00:00 2001 +From: Lenny Szubowicz +Date: Tue, 6 Jan 2015 11:17:01 -0500 +Subject: [PATCH] Fix buffer overflow when remove_from_boot_order removes + nothing + +Deleting a boot entry via "-b xxxx -B" also attempts to remove +that entry from boot order via a call to remove_from_boot_order. +Although unusual, it's possible that the entry being deleted is +not in boot order. Correct the handling of this case in +remove_from_boot_order, which malloc's space for the new boot +order list wrongly assuming that at least one entry will be +removed. However, if no entry is removed, then 2 bytes are +overwritten beyond the malloc'ed space. This can result in heap +corruption and possible termination via a SIGABRT if the +corruption is detected by the heap allocation routines. + +While there, simplify the routine to do the removal of boot +entries in place in the original data buffer, skip the +unnecessary BootOrder variable update if nothing got removed, +and free the malloc'ed boot_order struct on the way out. + +Resolves: RH BZ 1168019 + +Signed-off-by: Lenny Szubowicz +--- + src/efibootmgr/efibootmgr.c | 33 +++++++++++++++------------------ + 1 file changed, 15 insertions(+), 18 deletions(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index eb13942..1b55125 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -429,8 +429,7 @@ static int + remove_from_boot_order(uint16_t num) + { + efi_variable_t *boot_order = NULL; +- uint64_t new_data_size; +- uint16_t *new_data, *old_data; ++ uint16_t *data; + unsigned int old_i,new_i; + int rc; + +@@ -442,34 +441,32 @@ remove_from_boot_order(uint16_t num) + } + + /* We've now got an array (in boot_order->data) of the +- boot order. Simply copy the array, skipping the +- entry we're deleting. ++ boot order. Squeeze out any instance of the entry we're ++ deleting by shifting the remainder down. + */ +- old_data = (uint16_t *)(boot_order->data); +- /* Start with the same size */ +- new_data_size = boot_order->data_size - sizeof (*new_data); +- new_data = malloc(new_data_size); +- if (!new_data) +- return -1; ++ data = (uint16_t *)(boot_order->data); + + for (old_i=0,new_i=0; +- old_i < boot_order->data_size / sizeof(*new_data); ++ old_i < boot_order->data_size / sizeof(data[0]); + old_i++) { +- if (old_data[old_i] != num) { +- /* Copy this value */ +- new_data[new_i] = old_data[old_i]; ++ if (data[old_i] != num) { ++ if (new_i != old_i) ++ data[new_i] = data[old_i]; + new_i++; + } + } + +- /* Now new_data has what we need */ +- free(boot_order->data); +- boot_order->data = (uint8_t *)new_data; +- boot_order->data_size = new_data_size; ++ /* If nothing removed, no need to update the BootOrder variable */ ++ if (new_i == old_i) ++ goto all_done; ++ ++ /* BootOrder variable needs to be updated */ + efi_del_variable(EFI_GLOBAL_GUID, "BootOrder"); + rc = efi_set_variable(EFI_GLOBAL_GUID, "BootOrder", boot_order->data, + boot_order->data_size, boot_order->attributes); ++all_done: + free(boot_order->data); ++ free(boot_order); + return rc; + } + +-- +2.1.0 + diff --git a/SOURCES/0001-Make-EFI-redhat-shim.efi-the-default-bootloader-1036.patch b/SOURCES/0001-Make-EFI-redhat-shim.efi-the-default-bootloader-1036.patch new file mode 100644 index 0000000..c157b38 --- /dev/null +++ b/SOURCES/0001-Make-EFI-redhat-shim.efi-the-default-bootloader-1036.patch @@ -0,0 +1,44 @@ +From 0c833b1e099dd0ea4b9501baab579a79d9b561fb Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 14 Apr 2010 16:06:48 -0400 +Subject: [PATCH 1/1] Make \EFI\redhat\shim.efi the default bootloader + +Make \EFI\redhat\shim.efi the default bootloader instead of \elilo.efi . +--- + src/efibootmgr/efibootmgr.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 5af2cad..c2c7284 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -18,7 +18,7 @@ + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +- This must tie the EFI_DEVICE_PATH to /boot/efi/EFI/redhat/grub.efi ++ This must tie the EFI_DEVICE_PATH to /boot/efi/EFI/redhat/shim.efi + The EFI_DEVICE_PATH will look something like: + ACPI device path, length 12 bytes + Hardware Device Path, PCI, length 6 bytes +@@ -893,7 +893,7 @@ usage() + printf("\t-g | --gpt force disk with invalid PMBR to be treated as GPT\n"); + printf("\t-H | --acpi_hid XXXX set the ACPI HID (used with -i)\n"); + printf("\t-i | --iface name create a netboot entry for the named interface\n"); +- printf("\t-l | --loader name (defaults to \\EFI\\redhat\\grub.efi)\n"); ++ printf("\t-l | --loader name (defaults to \\EFI\\redhat\\shim.efi)\n"); + printf("\t-L | --label label Boot manager display label (defaults to \"Linux\")\n"); + printf("\t-n | --bootnext XXXX set BootNext to XXXX (hex)\n"); + printf("\t-N | --delete-bootnext delete BootNext\n"); +@@ -921,7 +921,7 @@ set_default_opts() + opts.active = -1; /* Don't set it */ + opts.timeout = -1; /* Don't set it */ + opts.edd10_devicenum = 0x80; +- opts.loader = "\\EFI\\redhat\\grub.efi"; ++ opts.loader = "\\EFI\\redhat\\shim.efi"; + opts.label = "Linux"; + opts.disk = "/dev/sda"; + opts.iface = NULL; +-- +1.9.3 + diff --git a/SOURCES/0001-Make-sure-BootOrder-gets-shortened-while-deleting.patch b/SOURCES/0001-Make-sure-BootOrder-gets-shortened-while-deleting.patch new file mode 100644 index 0000000..7501d1f --- /dev/null +++ b/SOURCES/0001-Make-sure-BootOrder-gets-shortened-while-deleting.patch @@ -0,0 +1,35 @@ +From c10728e51158b47302fc198d5a4e1720a420761e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 2 Feb 2015 11:13:20 -0500 +Subject: [PATCH] Make sure BootOrder gets shortened while deleting. + +So, what has happened is that a chunk of the patch for 1168019 got +dropped in a merge conflict error, and as a result the variable is never +actually shortened, and some of the old data is set as a result. + +Resolves: rhbz#1188313 + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 1b55125..b5d4147 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -462,6 +462,11 @@ remove_from_boot_order(uint16_t num) + + /* BootOrder variable needs to be updated */ + efi_del_variable(EFI_GLOBAL_GUID, "BootOrder"); ++ ++ if (new_i == 0) ++ goto all_done; ++ ++ boot_order->data_size = sizeof(data[0]) * new_i; + rc = efi_set_variable(EFI_GLOBAL_GUID, "BootOrder", boot_order->data, + boot_order->data_size, boot_order->attributes); + all_done: +-- +2.1.0 + diff --git a/SOURCES/0002-Make-the-return-path-something-coverity-can-actually.patch b/SOURCES/0002-Make-the-return-path-something-coverity-can-actually.patch new file mode 100644 index 0000000..0eaa503 --- /dev/null +++ b/SOURCES/0002-Make-the-return-path-something-coverity-can-actually.patch @@ -0,0 +1,45 @@ +From c2f19f1cb4fa2bc73d29d0e898e1799382a43735 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:29:43 -0400 +Subject: [PATCH 02/18] Make the return path something coverity can actually + understand. + +It was *correct* before, but there's no reason to do it that weird way. + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 17 ++++++++++------- + 1 file changed, 10 insertions(+), 7 deletions(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 5af2cad..1c65c07 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -805,14 +805,17 @@ show_boot_order() + + rc = read_boot_order(&boot_order); + +- if (rc < 0 && errno == ENOENT) { +- boot_order = calloc(1, sizeof (*boot_order)); +- rc = boot_order ? 0 : -1; +- } +- + if (rc < 0) { +- perror("show_boot_order()"); +- return; ++ if (errno == ENOENT) { ++ boot_order = calloc(1, sizeof (*boot_order)); ++ if (!boot_order) { ++ perror("show_boot_order()"); ++ return; ++ } ++ } else { ++ perror("show_boot_order()"); ++ return; ++ } + } + + /* We've now got an array (in boot_order->data) of the +-- +1.9.3 + diff --git a/SOURCES/0003-Don-t-leak-our-socket-s-fd-when-determining-network-.patch b/SOURCES/0003-Don-t-leak-our-socket-s-fd-when-determining-network-.patch new file mode 100644 index 0000000..1409bef --- /dev/null +++ b/SOURCES/0003-Don-t-leak-our-socket-s-fd-when-determining-network-.patch @@ -0,0 +1,58 @@ +From 611460349c214d9655a4ee06757fbcb5bdf6e2a3 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:32:59 -0400 +Subject: [PATCH 03/18] Don't leak our socket's fd when determining network + info. + +Covscan again. + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index 6b25dfe..8ba0e54 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -631,13 +631,16 @@ make_net_load_option(char *iface, uint8_t *buf, size_t size) + err = ioctl(fd, SIOCETHTOOL, &ifr); + if (err < 0) { + perror("Cannot get driver information"); ++ close(fd); + return -1; + } + + if (strncmp(drvinfo.bus_info, "virtio", 6) == 0) { + err = get_virt_pci(drvinfo.bus_info, &bus, &slot, &func); +- if (err < 0) ++ if (err < 0) { ++ close(fd); + return err; ++ } + } else { + /* The domain part was added in 2.6 kernels. + * Test for that first. */ +@@ -648,6 +651,7 @@ make_net_load_option(char *iface, uint8_t *buf, size_t size) + &bus, &slot, &func); + if (err != 3) { + perror("Couldn't parse device location string."); ++ close(fd); + return -1; + } + } +@@ -655,9 +659,11 @@ make_net_load_option(char *iface, uint8_t *buf, size_t size) + + err = ioctl(fd, SIOCGIFHWADDR, &ifr); + if (err < 0) { ++ close(fd); + perror("Cannot get hardware address."); + return -1; + } ++ close(fd); + + buf_offset = 0; + needed = make_acpi_device_path(opts.acpi_hid, opts.acpi_uid, buf, +-- +1.9.3 + diff --git a/SOURCES/0004-Fix-another-leaked-fd.patch b/SOURCES/0004-Fix-another-leaked-fd.patch new file mode 100644 index 0000000..9be2d6a --- /dev/null +++ b/SOURCES/0004-Fix-another-leaked-fd.patch @@ -0,0 +1,31 @@ +From 34410d6cf5a411f14f051045867cb2a7908e9330 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:34:12 -0400 +Subject: [PATCH 04/18] Fix another leaked fd. + +Covscan some more. + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index 8ba0e54..4218eb5 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -528,8 +528,10 @@ make_disk_load_option(char *disk, uint8_t *buf, size_t size) + needed = make_edd10_device_path(opts.edd10_devicenum, + buf, size); + } +- if (needed < 0) ++ if (needed < 0) { ++ close(disk_fd); + return needed; ++ } + buf_offset += needed; + } + +-- +1.9.3 + diff --git a/SOURCES/0005-Fix-some-minor-memory-leaks.patch b/SOURCES/0005-Fix-some-minor-memory-leaks.patch new file mode 100644 index 0000000..147c467 --- /dev/null +++ b/SOURCES/0005-Fix-some-minor-memory-leaks.patch @@ -0,0 +1,45 @@ +From 9b5950b9c6dd2322dadf2f54ecbbd24eddede278 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:40:29 -0400 +Subject: [PATCH 05/18] Fix some minor memory leaks. + +Well, one and not really another. Covscan is /almost/ a great tool. + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 1c65c07..88a4ef7 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -627,8 +627,11 @@ construct_boot_order(char *bootorder, int keep, + size_t data_size = 0; + + rc = parse_boot_order(bootorder, (uint16_t **)&data, &data_size); +- if (rc < 0 || data_size == 0) ++ if (rc < 0 || data_size == 0) { ++ if (data) /* this can't actually happen, but covscan believes */ ++ free(data); + return rc; ++ } + + if (!keep) { + *ret_data = data; +@@ -651,8 +654,11 @@ construct_boot_order(char *bootorder, int keep, + + size_t new_data_size = data_size + bo.data_size; + uint16_t *new_data = calloc(1, new_data_size); +- if (!new_data) ++ if (!new_data) { ++ if (data) ++ free(data); + return -1; ++ } + + memcpy(new_data, data, data_size); + memcpy(new_data + (data_size / sizeof (*new_data)), bo.data, +-- +1.9.3 + diff --git a/SOURCES/0006-Make-sure-data-created-for-load-options-is-freed.patch b/SOURCES/0006-Make-sure-data-created-for-load-options-is-freed.patch new file mode 100644 index 0000000..56cc1cf --- /dev/null +++ b/SOURCES/0006-Make-sure-data-created-for-load-options-is-freed.patch @@ -0,0 +1,50 @@ +From 2c557c3168b37b42d4dec1b5aa2298e7ce7597ad Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:46:04 -0400 +Subject: [PATCH 06/18] Make sure data created for load options is freed. + +Covscan... may not be right about this one. But it's better to be sure. + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index 4218eb5..7dc3c92 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -939,6 +939,7 @@ append_extra_args(uint8_t **data, size_t *data_size) + free(new_data); + if (ret < 0) + return -1; ++ new_data = NULL; + new_data_size = 0; + } + +@@ -946,15 +947,21 @@ append_extra_args(uint8_t **data, size_t *data_size) + ret = append_extra_args_unicode(&new_data, &new_data_size); + else + ret = append_extra_args_ascii(&new_data, &new_data_size); +- if (ret < 0) ++ if (ret < 0) { ++ if (new_data) /* this can't happen, but covscan believes */ ++ free(new_data); + return -1; ++ } + if (new_data_size) { + ret = add_new_data(data, data_size, new_data, new_data_size); + free(new_data); ++ new_data = NULL; + if (ret < 0) + return -1; + new_data_size = 0; + } + ++ if (new_data) /* once again, this can't happen, but covscan believes */ ++ free(new_data); + return 0; + } +-- +1.9.3 + diff --git a/SOURCES/0007-Fix-an-error-path-not-checking-the-return-right-in-m.patch b/SOURCES/0007-Fix-an-error-path-not-checking-the-return-right-in-m.patch new file mode 100644 index 0000000..5c6cc50 --- /dev/null +++ b/SOURCES/0007-Fix-an-error-path-not-checking-the-return-right-in-m.patch @@ -0,0 +1,49 @@ +From 6d7ef673de06cb7bfa5820848194e6eaad2fa8d4 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:47:57 -0400 +Subject: [PATCH 07/18] Fix an error path not checking the return right in + make_linux_load_option + +Covscan once again. + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index 7dc3c92..a131abe 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -722,7 +722,7 @@ make_linux_load_option(uint8_t **data, size_t *data_size) + size_t load_option_size = sizeof (*load_option); + efi_char16_t description[64]; + uint8_t *buf; +- size_t needed; ++ ssize_t needed; + off_t buf_offset = 0, desc_offset; + + load_option = calloc(1, sizeof (*load_option)); +@@ -754,11 +754,19 @@ make_linux_load_option(uint8_t **data, size_t *data_size) + + if (opts.iface) { + needed = make_net_load_option(opts.iface, NULL, 0); ++ if (needed < 0) { ++ free(buf); ++ return needed; ++ } + buf = extend(load_option, load_option_size, needed); + make_net_load_option(opts.iface, buf + buf_offset, needed); + buf_offset += needed; + } else { + needed = make_disk_load_option(opts.iface, NULL, 0); ++ if (needed < 0) { ++ free(buf); ++ return needed; ++ } + buf = extend(load_option, load_option_size, needed); + make_disk_load_option(opts.iface, buf + buf_offset, needed); + buf_offset += needed; +-- +1.9.3 + diff --git a/SOURCES/0008-Try-to-avoid-covscan-freaking-out-about-sscanf-with-.patch b/SOURCES/0008-Try-to-avoid-covscan-freaking-out-about-sscanf-with-.patch new file mode 100644 index 0000000..9e93de3 --- /dev/null +++ b/SOURCES/0008-Try-to-avoid-covscan-freaking-out-about-sscanf-with-.patch @@ -0,0 +1,59 @@ +From 2e40c869df425738ef06e7159a16adf5bf82c548 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 15:57:26 -0400 +Subject: [PATCH 08/18] Try to avoid covscan freaking out about sscanf with %n. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +covscan says: + + 5. efibootmgr-0.8.0/src/lib/disk.c:96:tainted_data_argument – Calling + function "fgets(char * restrict, int, FILE * restrict)" taints argument + "line". + 10. efibootmgr-0.8.0/src/lib/disk.c:103:vararg_transitive – Call to + "sscanf(char const * restrict, char const * restrict, ...)" with + tainted argument "line" taints "major". + 11. efibootmgr-0.8.0/src/lib/disk.c:103:vararg_transitive – Call to + "sscanf(char const * restrict, char const * restrict, ...)" with + tainted argument "line" taints "scanned". + 13. efibootmgr-0.8.0/src/lib/disk.c:103:tainted_data – Using tainted + variable "scanned" as an index into an array "line". + +I *think* that's really complaining that if sscanf fails before +processing %n, then "scanned" is indeterminate here. So I've assigned +it to 0. + +Either way, if any of that goes wrong, the code's going to completely +fail. + +Signed-off-by: Peter Jones +--- + src/lib/disk.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/lib/disk.c b/src/lib/disk.c +index 904010b..4536a67 100644 +--- a/src/lib/disk.c ++++ b/src/lib/disk.c +@@ -56,7 +56,7 @@ get_virtblk_major(void) + } + while (fgets(line, sizeof line, f) != NULL) { + size_t len = strlen(line); +- int major, scanned; ++ int major, scanned = 0; + + if (len == 0 || line[len - 1] != '\n') { + break; +@@ -95,7 +95,7 @@ get_nvme_major(void) + } + while (fgets(line, sizeof line, f) != NULL) { + size_t len = strlen(line); +- int major, scanned; ++ int major, scanned = 0; + + if (len == 0 || line[len - 1] != '\n') { + break; +-- +1.9.3 + diff --git a/SOURCES/0009-Get-rid-of-an-invalid-comparison.patch b/SOURCES/0009-Get-rid-of-an-invalid-comparison.patch new file mode 100644 index 0000000..a366d4b --- /dev/null +++ b/SOURCES/0009-Get-rid-of-an-invalid-comparison.patch @@ -0,0 +1,28 @@ +From 0521d90c3d081bc45aad4815698884ae32e35041 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:02:58 -0400 +Subject: [PATCH 09/18] Get rid of an invalid comparison. + +Covscan. + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 88a4ef7..5280180 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -1008,7 +1008,7 @@ parse_opts(int argc, char **argv) + break; + case 'b': + rc = sscanf(optarg, "%X", &num); +- if (rc == 1 && num >= 0 && num < 0xffff) { ++ if (rc == 1 && num < 0xffff) { + opts.bootnum = num; + } else { + fprintf (stderr,"invalid hex value %s\n",optarg); +-- +1.9.3 + diff --git a/SOURCES/0010-Covscan-can-t-tell-that-we-re-not-filling-a-buffer.patch b/SOURCES/0010-Covscan-can-t-tell-that-we-re-not-filling-a-buffer.patch new file mode 100644 index 0000000..e83ed6c --- /dev/null +++ b/SOURCES/0010-Covscan-can-t-tell-that-we-re-not-filling-a-buffer.patch @@ -0,0 +1,41 @@ +From 58bfbf6c4fed6dfb875cd59ae9e04986a1cdcd2c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:07:02 -0400 +Subject: [PATCH 10/18] Covscan can't tell that we're not filling a buffer... + +Because the pattern here is: + +rc = func_call(buf, buflen) +if (rc < 0) + return error; +buflen = rc; +buf = calloc(1, buflen) +if (!buf) + return error; +rc = func_call(buf, buflen); + +Covscan thinks the first func_call() might actually be doing something +to buf. It isn't, but that's not obvious. So make it NULL and 0 +instead of buf and buflen on the first call. + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 5280180..31807a9 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -772,7 +772,7 @@ show_boot_vars() + continue; + } + +- rc = unparse_raw_text(text_path, text_path_len, ++ rc = unparse_raw_text(NULL, 0, + ((uint8_t *)path) + + load_option->file_path_list_length, + optional_data_len); +-- +1.9.3 + diff --git a/SOURCES/0011-Don-t-free-something-that-shouldn-t-ever-be-non-NULL.patch b/SOURCES/0011-Don-t-free-something-that-shouldn-t-ever-be-non-NULL.patch new file mode 100644 index 0000000..caca252 --- /dev/null +++ b/SOURCES/0011-Don-t-free-something-that-shouldn-t-ever-be-non-NULL.patch @@ -0,0 +1,57 @@ +From 939f9700414785f51579ba25a2c76a90d161ec31 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:15:27 -0400 +Subject: [PATCH 11/18] Don't free something that shouldn't ever be non-NULL. + +Instead, check and error if it's non-NULL. + +(Covscan, which got this completely wrong.) + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 8 ++------ + 1 file changed, 2 insertions(+), 6 deletions(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index a131abe..f604a1a 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -792,7 +792,7 @@ append_extra_args_ascii(uint8_t **data, size_t *data_size) + int i; + unsigned long usedchars=0; + +- if (!data) ++ if (!data || *data) + return -1; + + for (i=opts.optind; i < opts.argc; i++) { +@@ -816,8 +816,6 @@ append_extra_args_ascii(uint8_t **data, size_t *data_size) + if (!new_data) + return 0; + +- if (*data) +- free(*data); + *data = (uint8_t *)new_data; + *data_size = usedchars; + +@@ -831,7 +829,7 @@ append_extra_args_unicode(uint8_t **data, size_t *data_size) + int i; + unsigned long usedchars=0; + +- if (!data) ++ if (!data || *data) + return -1; + + for (i = opts.optind; i < opts.argc; i++) { +@@ -857,8 +855,6 @@ append_extra_args_unicode(uint8_t **data, size_t *data_size) + if (!new_data) + return 0; + +- if (*data) +- free(*data); + *data = (uint8_t *)new_data; + *data_size = usedchars * sizeof (*new_data); + +-- +1.9.3 + diff --git a/SOURCES/0012-Don-t-reuse-a-pointer-to-static-data-and-free-condit.patch b/SOURCES/0012-Don-t-reuse-a-pointer-to-static-data-and-free-condit.patch new file mode 100644 index 0000000..ab92eeb --- /dev/null +++ b/SOURCES/0012-Don-t-reuse-a-pointer-to-static-data-and-free-condit.patch @@ -0,0 +1,53 @@ +From ebf8073e904f21fd333f5a74bd3942c3e8840f0e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:20:04 -0400 +Subject: [PATCH 12/18] Don't reuse a pointer to static data and free + conditionally. + +Instead, use a second pointer and free that, because poor covscan can't +figure out what's going on. + +Signed-off-by: Peter Jones +--- + src/lib/unparse_path.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/src/lib/unparse_path.c b/src/lib/unparse_path.c +index 431dc06..5a69fde 100644 +--- a/src/lib/unparse_path.c ++++ b/src/lib/unparse_path.c +@@ -325,6 +325,7 @@ unparse_media_hard_drive_path(char *buffer, size_t buffer_size, + char text_uuid[40], *sig=text_uuid; + char a[16], b[16], c[16]; + int rc = 0; ++ char *sig_allocated = NULL; + + switch (hd->signature_type) { + case 0x00: +@@ -339,9 +340,11 @@ unparse_media_hard_drive_path(char *buffer, size_t buffer_size, + return -1; + break; + case 0x02: /* GPT */ +- rc = efi_guid_to_str((efi_guid_t *)hd->signature, &sig); ++ rc = efi_guid_to_str((efi_guid_t *)hd->signature, ++ &sig_allocated); + if (rc < 0) + return rc; ++ sig = sig_allocated; + break; + default: + return 0; +@@ -352,8 +355,8 @@ unparse_media_hard_drive_path(char *buffer, size_t buffer_size, + get(b, hd->start), + get(c, hd->size), + sig); +- if (hd->signature_type == 0x02) +- free(sig); ++ if (sig_allocated) ++ free(sig_allocated); + return rc; + } + +-- +1.9.3 + diff --git a/SOURCES/0013-Handle-the-case-where-there-are-no-EFI-variables.patch b/SOURCES/0013-Handle-the-case-where-there-are-no-EFI-variables.patch new file mode 100644 index 0000000..8febab2 --- /dev/null +++ b/SOURCES/0013-Handle-the-case-where-there-are-no-EFI-variables.patch @@ -0,0 +1,28 @@ +From 54879fe911ed1b57e15d641ff8c6656e915f3f50 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:22:21 -0400 +Subject: [PATCH 13/18] Handle the case where there are no EFI variables. + +So we're on an EFI machine with no variables, eh covscan? + +Signed-off-by: Peter Jones +--- + src/lib/efi.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lib/efi.c b/src/lib/efi.c +index f604a1a..7cdc884 100644 +--- a/src/lib/efi.c ++++ b/src/lib/efi.c +@@ -112,7 +112,7 @@ read_var_names(filter_t filter, char ***namelist) + + newlist = tmp; + } +- if (rc == 0) { ++ if (rc == 0 && newlist) { + qsort(newlist, nentries, sizeof (char *), cmpstringp); + *namelist = newlist; + } else { +-- +1.9.3 + diff --git a/SOURCES/0014-Make-a-free-non-conditional-since-the-condition-can-.patch b/SOURCES/0014-Make-a-free-non-conditional-since-the-condition-can-.patch new file mode 100644 index 0000000..fda83a3 --- /dev/null +++ b/SOURCES/0014-Make-a-free-non-conditional-since-the-condition-can-.patch @@ -0,0 +1,30 @@ +From 79c14e7a87eee655ae27427c560903e78e2c09a3 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:24:03 -0400 +Subject: [PATCH 14/18] Make a free non-conditional since the condition can't + be ture. + +Covscan again. I wonder if it'll complain about this. + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index 31807a9..f9c25e0 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -463,8 +463,7 @@ read_boot_u16(const char *name) + } + + rc = data[0]; +- if (data != NULL) +- free(data); ++ free(data); + return rc; + } + +-- +1.9.3 + diff --git a/SOURCES/0015-Check-malloc-return.patch b/SOURCES/0015-Check-malloc-return.patch new file mode 100644 index 0000000..65bef7d --- /dev/null +++ b/SOURCES/0015-Check-malloc-return.patch @@ -0,0 +1,28 @@ +From 4542b2216b6a85d91eb3c5b78e914b2b82f865fa Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:49:51 -0400 +Subject: [PATCH 15/18] Check malloc() return. + +Covscan. + +Signed-off-by: Peter Jones +--- + src/efibootmgr/efibootmgr.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c +index f9c25e0..01c1505 100644 +--- a/src/efibootmgr/efibootmgr.c ++++ b/src/efibootmgr/efibootmgr.c +@@ -330,6 +330,8 @@ add_to_boot_order(uint16_t num) + old_data = (uint16_t *)boot_order->data; + new_data_size = boot_order->data_size + sizeof(uint16_t); + new_data = malloc(new_data_size); ++ if (!new_data) ++ return -1; + + new_data[0] = num; + memcpy(new_data+1, old_data, boot_order->data_size); +-- +1.9.3 + diff --git a/SOURCES/0016-Check-open-s-return-correctly.patch b/SOURCES/0016-Check-open-s-return-correctly.patch new file mode 100644 index 0000000..b05fb4e --- /dev/null +++ b/SOURCES/0016-Check-open-s-return-correctly.patch @@ -0,0 +1,28 @@ +From 4bba8fefd9779edda6c1ac89812c3882a277a25d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:50:08 -0400 +Subject: [PATCH 16/18] Check open()s return correctly. + +Covscan. + +Signed-off-by: Peter Jones +--- + src/lib/disk.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lib/disk.c b/src/lib/disk.c +index 4536a67..337909e 100644 +--- a/src/lib/disk.c ++++ b/src/lib/disk.c +@@ -328,7 +328,7 @@ disk_get_ide_pci(int fd, + sprintf(procname, "/proc/ide/ide%d/config", info.controllernum); + + procfd = open(procname, O_RDONLY); +- if (!procfd) { ++ if (procfd < 0) { + perror("opening /proc/ide/ide*/config"); + return 1; + } +-- +1.9.3 + diff --git a/SOURCES/0017-Check-lseek-for-errors.patch b/SOURCES/0017-Check-lseek-for-errors.patch new file mode 100644 index 0000000..211e773 --- /dev/null +++ b/SOURCES/0017-Check-lseek-for-errors.patch @@ -0,0 +1,41 @@ +From 3cdcc7ef32e90c411d7f4e14a896f9bf7afa4f29 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 16:56:49 -0400 +Subject: [PATCH 17/18] Check lseek() for errors. + +Covscan. + +Signed-off-by: Peter Jones +--- + src/lib/gpt.c | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/src/lib/gpt.c b/src/lib/gpt.c +index 67a8c41..fc2acf3 100644 +--- a/src/lib/gpt.c ++++ b/src/lib/gpt.c +@@ -221,6 +221,7 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) + void *iobuf; + size_t iobuf_size; + int rc; ++ off_t new_offset; + + iobuf_size = lcm(bytes, sector_size); + rc = posix_memalign(&iobuf, sector_size, iobuf_size); +@@ -228,8 +229,11 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) + return rc; + memset(iobuf, 0, bytes); + +- +- lseek(fd, offset, SEEK_SET); ++ new_offset = lseek(fd, offset, SEEK_SET); ++ if (new_offset == (off_t)-1) { ++ free(iobuf); ++ return 0; ++ } + bytesread = read(fd, iobuf, iobuf_size); + memcpy(buffer, iobuf, bytes); + free(iobuf); +-- +1.9.3 + diff --git a/SOURCES/0018-Don-t-leak-our-partition-table-structures.patch b/SOURCES/0018-Don-t-leak-our-partition-table-structures.patch new file mode 100644 index 0000000..4b10af9 --- /dev/null +++ b/SOURCES/0018-Don-t-leak-our-partition-table-structures.patch @@ -0,0 +1,44 @@ +From 38fa9b2ceb1095c320ee2aa7482a85fc91ec590d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 10 Sep 2014 17:03:23 -0400 +Subject: [PATCH 18/18] Don't leak our partition table structures. + +Covscan once more. + +Signed-off-by: Peter Jones +--- + src/lib/gpt.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/src/lib/gpt.c b/src/lib/gpt.c +index fc2acf3..8cb0e39 100644 +--- a/src/lib/gpt.c ++++ b/src/lib/gpt.c +@@ -612,6 +612,7 @@ gpt_disk_get_partition_info(int fd, + { + gpt_header *gpt = NULL; + gpt_entry *ptes = NULL, *p; ++ int rc = 0; + + if (!find_valid_gpt(fd, &gpt, &ptes)) + return 1; +@@ -628,9 +629,14 @@ gpt_disk_get_partition_info(int fd, + sizeof (p->unique_partition_guid)); + } else { + fprintf (stderr,"partition %d is not valid\n", num); +- return 1; ++ rc = 1; + } +- return 0; ++ if (ptes) ++ free(ptes); ++ if (gpt) ++ free(gpt); ++ ++ return rc; + } + + /* +-- +1.9.3 + diff --git a/SOURCES/efibootmgr-0.5.4-Remove-device-path-padding-on-non-Itanium.patch b/SOURCES/efibootmgr-0.5.4-Remove-device-path-padding-on-non-Itanium.patch deleted file mode 100644 index 240aa69..0000000 --- a/SOURCES/efibootmgr-0.5.4-Remove-device-path-padding-on-non-Itanium.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 2d8f962284f40b918c0fc8385e58fcba219ddc12 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Wed, 28 Nov 2012 17:13:24 -0500 -Subject: [PATCH 2/5] Remove device path padding on non-Itanium - -This code predates EFI support on any x86 hardware, and it's a strict -violation of the specification. Windows doesn't do it either. ---- - src/include/efi.h | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/include/efi.h b/src/include/efi.h -index be667ae..c2ac853 100644 ---- a/src/include/efi.h -+++ b/src/include/efi.h -@@ -294,7 +294,9 @@ typedef struct { - uint8_t signature[16]; - uint8_t mbr_type; - uint8_t signature_type; -+#ifdef __ia64 - uint8_t padding[6]; /* Emperically needed */ -+#endif - } __attribute__((packed)) HARDDRIVE_DEVICE_PATH; - - typedef struct { --- -1.8.0 - diff --git a/SOURCES/efibootmgr-0.5.4-Work-around-broken-Apple-firmware.patch b/SOURCES/efibootmgr-0.5.4-Work-around-broken-Apple-firmware.patch deleted file mode 100644 index a1d9831..0000000 --- a/SOURCES/efibootmgr-0.5.4-Work-around-broken-Apple-firmware.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 6edc3ed5479b575f87eb51e335957b05fdd04fe8 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Wed, 28 Nov 2012 16:49:18 -0500 -Subject: [PATCH 1/5] Work around broken Apple firmware - -Alex Murray found that Apple's firmware sets an invalid EFI attribute on -BootCurrent, which newer versions of the kernel then reject. This patch -from him simply masks off the extraneous bit. ---- - src/lib/efivars_sysfs.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/lib/efivars_sysfs.c b/src/lib/efivars_sysfs.c -index 182c70f..ea87325 100644 ---- a/src/lib/efivars_sysfs.c -+++ b/src/lib/efivars_sysfs.c -@@ -55,6 +55,10 @@ sysfs_read_variable(const char *name, efi_variable_t *var) - return EFI_INVALID_PARAMETER; - } - close(fd); -+ /* latest apple firmware sets high bit which appears invalid -+ to the linux kernel if we write it back so lets zero it out -+ if it is set since it would be invalid to set it anyway */ -+ var->Attributes = var->Attributes & ~(1 << 31); - return var->Status; - } - --- -1.8.0 - diff --git a/SOURCES/efibootmgr-0.5.4-default-to-shim.patch b/SOURCES/efibootmgr-0.5.4-default-to-shim.patch deleted file mode 100644 index 538166d..0000000 --- a/SOURCES/efibootmgr-0.5.4-default-to-shim.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 836e58668167e82c5ffcb66f3f390d2c52217f6a Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 14 Apr 2010 16:06:48 -0400 -Subject: [PATCH] Make \EFI\redhat\shim.efi the default bootloader (#1036022) - -Make \EFI\redhat\shim.efi the default bootloader instead of \elilo.efi . ---- - src/efibootmgr/efibootmgr.c | 6 +++--- - 1 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c -index 5db0d9e..b984143 100644 ---- a/src/efibootmgr/efibootmgr.c -+++ b/src/efibootmgr/efibootmgr.c -@@ -18,7 +18,7 @@ - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -- This must tie the EFI_DEVICE_PATH to /boot/efi/elilo.efi -+ This must tie the EFI_DEVICE_PATH to /boot/efi/EFI/redhat/shim.efi - The EFI_DEVICE_PATH will look something like: - ACPI device path, length 12 bytes - Hardware Device Path, PCI, length 6 bytes -@@ -779,7 +779,7 @@ usage() - printf("\t-g | --gpt force disk with invalid PMBR to be treated as GPT\n"); - printf("\t-H | --acpi_hid XXXX set the ACPI HID (used with -i)\n"); - printf("\t-i | --iface name create a netboot entry for the named interface\n"); -- printf("\t-l | --loader name (defaults to \\elilo.efi)\n"); -+ printf("\t-l | --loader name (defaults to \\EFI\\redhat\\shim.efi)\n"); - printf("\t-L | --label label Boot manager display label (defaults to \"Linux\")\n"); - printf("\t-n | --bootnext XXXX set BootNext to XXXX (hex)\n"); - printf("\t-N | --delete-bootnext delete BootNext\n"); -@@ -807,7 +807,7 @@ set_default_opts() - opts.active = -1; /* Don't set it */ - opts.timeout = -1; /* Don't set it */ - opts.edd10_devicenum = 0x80; -- opts.loader = "\\elilo.efi"; -+ opts.loader = "\\EFI\\redhat\\shim.efi"; - opts.label = "Linux"; - opts.disk = "/dev/sda"; - opts.iface = NULL; --- -1.7.0.1 - diff --git a/SOURCES/efibootmgr-0.5.4-fix-disk-minor-number-discovery.patch b/SOURCES/efibootmgr-0.5.4-fix-disk-minor-number-discovery.patch deleted file mode 100644 index e9b5358..0000000 --- a/SOURCES/efibootmgr-0.5.4-fix-disk-minor-number-discovery.patch +++ /dev/null @@ -1,29 +0,0 @@ -From f9f4ee75ad745637a47bf17ed968101b1ffbcc1d Mon Sep 17 00:00:00 2001 -From: Matt Domsch -Date: Thu, 23 Jul 2009 14:20:19 -0500 -Subject: [PATCH 4/5] fix disk minor number discovery - -Raymund Will noted disk_info_from_fd() incorrectly used logical && -instead of bitwise & when obtaining the minor number. - -Reported in https://bugzilla.novell.com/show_bug.cgi?id=524529#c1 ---- - src/lib/disk.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lib/disk.c b/src/lib/disk.c -index ebfe619..8ad590b 100644 ---- a/src/lib/disk.c -+++ b/src/lib/disk.c -@@ -55,7 +55,7 @@ disk_info_from_fd(int fd, - return 1; - } - major = buf.st_dev >> 8; -- minor = buf.st_dev && 0xFF; -+ minor = buf.st_dev & 0xFF; - - /* IDE disks can have up to 64 partitions, or 6 bits worth, - * and have one bit for the disk number. --- -1.8.0 - diff --git a/SOURCES/efibootmgr-0.5.4-fix-minor-memory-leak.patch b/SOURCES/efibootmgr-0.5.4-fix-minor-memory-leak.patch deleted file mode 100644 index 1ff4ce3..0000000 --- a/SOURCES/efibootmgr-0.5.4-fix-minor-memory-leak.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 36c3a19c62cc3b6841e363712c3c78ef5915122d Mon Sep 17 00:00:00 2001 -From: Matt Domsch -Date: Thu, 23 Jul 2009 14:18:11 -0500 -Subject: [PATCH 3/5] fix minor memory leak - -David Binderman noted new_data was being allocated but not freed. Not -a big deal as the program exits soon thereafter (and is thus freed), -but worth fixing anyhow. - -Fixes https://bugzilla.novell.com/show_bug.cgi?id=524529#c1 ---- - src/efibootmgr/efibootmgr.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c -index b984143..de67af0 100644 ---- a/src/efibootmgr/efibootmgr.c -+++ b/src/efibootmgr/efibootmgr.c -@@ -328,6 +328,7 @@ add_to_boot_order(uint16_t num) - /* Now new_data has what we need */ - memcpy(&(boot_order.Data), new_data, new_data_size); - boot_order.DataSize = new_data_size; -+ free(new_data); - return create_or_edit_variable(&boot_order); - } - --- -1.8.0 - diff --git a/SOURCES/efibootmgr-0.5.4-make_boot_var-does-not-check-for-failed-status-with-.patch b/SOURCES/efibootmgr-0.5.4-make_boot_var-does-not-check-for-failed-status-with-.patch deleted file mode 100644 index 75374ac..0000000 --- a/SOURCES/efibootmgr-0.5.4-make_boot_var-does-not-check-for-failed-status-with-.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 5fcfccb39089febb89945b841f489b5acc7638ce Mon Sep 17 00:00:00 2001 -From: Lane Winner -Date: Tue, 24 Apr 2012 12:58:57 -0500 -Subject: [PATCH 5/5] make_boot_var does not check for failed status with - create_variable. This can result in a memory leak. - Additionally the user should be notified of the - problem. - -We encounter this issue on one system after filling up the UEFI boot list -with dummy devices. - -The patch fix the problem. It was verified on a Mensa system using RHEL 6.0 - -Signed-off-by: Yinghai Lu ---- - src/efibootmgr/efibootmgr.c | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c -index de67af0..236365a 100644 ---- a/src/efibootmgr/efibootmgr.c -+++ b/src/efibootmgr/efibootmgr.c -@@ -239,6 +239,7 @@ warn_duplicate_name(list_t *boot_list) - static var_entry_t * - make_boot_var(list_t *boot_list) - { -+ efi_status_t status; - var_entry_t *boot; - int free_number; - list_t *pos; -@@ -271,7 +272,12 @@ make_boot_var(list_t *boot_list) - free(boot); - return NULL; - } -- create_variable(&boot->var_data); -+ -+ status = create_variable(&boot->var_data); -+ if (status != EFI_SUCCESS) { -+ free(boot); -+ return NULL; -+ } - list_add_tail(&boot->list, boot_list); - return boot; - } --- -1.8.0 - diff --git a/SOURCES/efibootmgr-0.5.4-support-4k-sectors.patch b/SOURCES/efibootmgr-0.5.4-support-4k-sectors.patch deleted file mode 100644 index c380c61..0000000 --- a/SOURCES/efibootmgr-0.5.4-support-4k-sectors.patch +++ /dev/null @@ -1,176 +0,0 @@ -Return-Path: pjones@redhat.com -Received: from zmta02.collab.prod.int.phx2.redhat.com (LHLO - zmta02.collab.prod.int.phx2.redhat.com) (10.5.5.32) by - mail04.corp.redhat.com with LMTP; Wed, 14 Jul 2010 14:25:52 -0400 (EDT) -Received: from localhost (localhost.localdomain [127.0.0.1]) - by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id B69C19F152 - for ; Wed, 14 Jul 2010 14:25:52 -0400 (EDT) -Received: from zmta02.collab.prod.int.phx2.redhat.com ([127.0.0.1]) - by localhost (zmta02.collab.prod.int.phx2.redhat.com [127.0.0.1]) (amavisd-new, port 10024) - with ESMTP id jCHcGZehMQ5J for ; - Wed, 14 Jul 2010 14:25:52 -0400 (EDT) -Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) - by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id A601C9F14C - for ; Wed, 14 Jul 2010 14:25:52 -0400 (EDT) -Received: from pjones4.install.bos.redhat.com (pjones4.install.bos.redhat.com [10.16.52.154]) - by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6EIPpGh017771; - Wed, 14 Jul 2010 14:25:52 -0400 -From: Peter Jones -To: Matt Domsch -Cc: Peter Jones , Stuart Hayes -Subject: [efibootmgr patch] Handle sector_size != 512. -Date: Wed, 14 Jul 2010 14:26:49 -0400 -Message-Id: <1279132009-26635-1-git-send-email-pjones@redhat.com> -In-Reply-To: <1279121617-17961-1-git-send-email-pjones@redhat.com> -References: <1279121617-17961-1-git-send-email-pjones@redhat.com> -X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 - -Disks can have 4kB sectors now, so don't just bail out when that's the -case. ---- - src/include/disk.h | 3 +++ - src/lib/disk.c | 43 +++++++++++++++++++++++++++++++++---------- - src/lib/gpt.c | 30 ++++++++++++++---------------- - 3 files changed, 50 insertions(+), 26 deletions(-) - -diff --git a/src/include/disk.h b/src/include/disk.h -index eb93d10..8aa37d7 100644 ---- a/src/include/disk.h -+++ b/src/include/disk.h -@@ -65,6 +65,9 @@ enum _interface_type {interface_type_unknown, - ata, atapi, scsi, usb, - i1394, fibre, i2o, md}; - -+ -+unsigned int lcm(unsigned int x, unsigned int y); -+ - int disk_get_pci(int fd, - unsigned char *bus, - unsigned char *device, -diff --git a/src/lib/disk.c b/src/lib/disk.c -index 883864f..9c3a878 100644 ---- a/src/lib/disk.c -+++ b/src/lib/disk.c -@@ -420,6 +420,27 @@ get_sector_size(int filedes) - return sector_size; - } - -+/************************************************************ -+ * lcm -+ * Requires: -+ * - numbers of which to find the lowest common multiple -+ * Modifies: nothing -+ * Returns: -+ * lowest common multiple of x and y -+ ************************************************************/ -+unsigned int -+lcm(unsigned int x, unsigned int y) -+{ -+ unsigned int m = x, n = y, o; -+ -+ while ((o = m % n)) { -+ m = n; -+ n = o; -+ } -+ -+ return (x / n) * y; -+} -+ - /** - * disk_get_partition_info() - * @fd - open file descriptor to disk -@@ -442,26 +463,27 @@ disk_get_partition_info (int fd, - uint8_t *mbr_type, uint8_t *signature_type) - { - legacy_mbr *mbr; -- void *mbr_unaligned; -+ void *mbr_sector; -+ size_t mbr_size; - off_t offset; - int this_bytes_read = 0; - int gpt_invalid=0, mbr_invalid=0; - int rc=0; - int sector_size = get_sector_size(fd); - -- if (sizeof(*mbr) != sector_size) -- return 1; -- mbr_unaligned = malloc(sizeof(*mbr)+sector_size-1); -- mbr = (legacy_mbr *) -- (((unsigned long)mbr_unaligned + sector_size - 1) & -- ~(unsigned long)(sector_size-1)); -- memset(mbr, 0, sizeof(*mbr)); -+ -+ mbr_size = lcm(sizeof(*mbr), sector_size); -+ if ((rc = posix_memalign(&mbr_sector, sector_size, mbr_size)) != 0) -+ goto error; -+ memset(mbr_sector, '\0', mbr_size); -+ - offset = lseek(fd, 0, SEEK_SET); -- this_bytes_read = read(fd, mbr, sizeof(*mbr)); -+ this_bytes_read = read(fd, mbr_sector, mbr_size); - if (this_bytes_read < sizeof(*mbr)) { - rc=1; - goto error_free_mbr; - } -+ mbr = (legacy_mbr *)mbr_sector; - gpt_invalid = gpt_disk_get_partition_info(fd, num, - start, size, - signature, -@@ -479,7 +501,8 @@ disk_get_partition_info (int fd, - } - } - error_free_mbr: -- free(mbr_unaligned); -+ free(mbr_sector); -+ error: - return rc; - } - -diff --git a/src/lib/gpt.c b/src/lib/gpt.c -index d90ddaf..83e7a94 100644 ---- a/src/lib/gpt.c -+++ b/src/lib/gpt.c -@@ -215,26 +215,24 @@ read_lastoddsector(int fd, uint64_t lba, void *buffer, size_t count) - static ssize_t - read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) - { -- int sector_size = get_sector_size(fd); -- off_t offset = lba * sector_size; -+ int sector_size = get_sector_size(fd); -+ off_t offset = lba * sector_size; - ssize_t bytesread; -- void *aligned; -- void *unaligned; -- -- if (bytes % sector_size) -- return EINVAL; -+ void *iobuf; -+ size_t iobuf_size; -+ int rc; - -- unaligned = malloc(bytes+sector_size-1); -- aligned = (void *) -- (((unsigned long)unaligned + sector_size - 1) & -- ~(unsigned long)(sector_size-1)); -- memset(aligned, 0, bytes); -+ iobuf_size = lcm(bytes, sector_size); -+ rc = posix_memalign(&iobuf, sector_size, iobuf_size); -+ if (rc) -+ return rc; -+ memset(iobuf, 0, bytes); - - -- lseek(fd, offset, SEEK_SET); -- bytesread = read(fd, aligned, bytes); -- memcpy(buffer, aligned, bytesread); -- free(unaligned); -+ lseek(fd, offset, SEEK_SET); -+ bytesread = read(fd, iobuf, iobuf_size); -+ memcpy(buffer, iobuf, bytes); -+ free(iobuf); - - /* Kludge. This is necessary to read/write the last - block of an odd-sized disk, until Linux 2.5.x kernel fixes. --- -1.7.1.1 - diff --git a/SPECS/efibootmgr.spec b/SPECS/efibootmgr.spec index 4464dae..ffbd90e 100644 --- a/SPECS/efibootmgr.spec +++ b/SPECS/efibootmgr.spec @@ -1,27 +1,43 @@ Summary: EFI Boot Manager Name: efibootmgr -Version: 0.5.4 -Release: 18%{?dist} +Version: 0.8.0 +Release: 5%{?dist} Group: System Environment/Base License: GPLv2+ -URL: http://linux.dell.com/%{name}/ +URL: http://github.com/vathpela/%{name}/ BuildRequires: pciutils-devel, zlib-devel, git +BuildRequires: efivar-libs, efivar-devel BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXXXX) # EFI/UEFI don't exist on PPC -ExclusiveArch: %{ix86} x86_64 ia64 aarch64 +ExclusiveArch: x86_64 aarch64 # for RHEL / Fedora when efibootmgr was part of the elilo package -Conflicts: elilo <= 3.6-5 -Obsoletes: elilo <= 3.6-5 - -Source0: http://linux.dell.com/%{name}/permalink/%{name}-%{version}.tar.gz -Patch0: efibootmgr-0.5.4-default-to-shim.patch -Patch1: efibootmgr-0.5.4-support-4k-sectors.patch -Patch2: efibootmgr-0.5.4-Work-around-broken-Apple-firmware.patch -Patch3: efibootmgr-0.5.4-Remove-device-path-padding-on-non-Itanium.patch -Patch4: efibootmgr-0.5.4-fix-minor-memory-leak.patch -Patch5: efibootmgr-0.5.4-fix-disk-minor-number-discovery.patch -Patch6: efibootmgr-0.5.4-make_boot_var-does-not-check-for-failed-status-with-.patch +Conflicts: elilo <= 3.6-6 +Obsoletes: elilo <= 3.6-6 + +Source0: https://github.com/vathpela/%{name}/releases/download/%{name}-%{version}/%{name}-%{version}.tar.bz2 +Patch0000: 0001-Make-EFI-redhat-shim.efi-the-default-bootloader-1036.patch +Patch0001: 0001-Fix-a-bad-allocation-size.patch +Patch0002: 0002-Make-the-return-path-something-coverity-can-actually.patch +Patch0003: 0003-Don-t-leak-our-socket-s-fd-when-determining-network-.patch +Patch0004: 0004-Fix-another-leaked-fd.patch +Patch0005: 0005-Fix-some-minor-memory-leaks.patch +Patch0006: 0006-Make-sure-data-created-for-load-options-is-freed.patch +Patch0007: 0007-Fix-an-error-path-not-checking-the-return-right-in-m.patch +Patch0008: 0008-Try-to-avoid-covscan-freaking-out-about-sscanf-with-.patch +Patch0009: 0009-Get-rid-of-an-invalid-comparison.patch +Patch0010: 0010-Covscan-can-t-tell-that-we-re-not-filling-a-buffer.patch +Patch0011: 0011-Don-t-free-something-that-shouldn-t-ever-be-non-NULL.patch +Patch0012: 0012-Don-t-reuse-a-pointer-to-static-data-and-free-condit.patch +Patch0013: 0013-Handle-the-case-where-there-are-no-EFI-variables.patch +Patch0014: 0014-Make-a-free-non-conditional-since-the-condition-can-.patch +Patch0015: 0015-Check-malloc-return.patch +Patch0016: 0016-Check-open-s-return-correctly.patch +Patch0017: 0017-Check-lseek-for-errors.patch +Patch0018: 0018-Don-t-leak-our-partition-table-structures.patch +Patch0019: 0001-Don-t-error-on-unset-BootOrder-when-we-re-trying-to-.patch +Patch0020: 0001-Fix-buffer-overflow-when-remove_from_boot_order-remo.patch +Patch0021: 0001-Make-sure-BootOrder-gets-shortened-while-deleting.patch %description %{name} displays and allows the user to edit the Intel Extensible @@ -32,11 +48,13 @@ http://developer.intel.com/technology/efi/efi.htm and http://uefi.org/. %prep %setup -q git init -git config user.email "pjones@fedoraproject.org" -git config user.name "Fedora Ninjas" +git config user.email "example@example.com" +git config user.name "RHEL Ninjas" git add . git commit -a -q -m "%{version} baseline." -git am %{patches} +git am %{patches} - 0.5.4-18 -- Enable efibootmgr on aarch64 platforms - Resolves: rhbz#1055728 - -* Mon Jan 20 2014 Peter Jones - 0.5.4-17 -- Make \EFI\redhat\shim.efi the default bootloader - Resolves: rhbz#1036022 - -* Fri Dec 27 2013 Daniel Mach - 0.5.4-16 -- Mass rebuild 2013-12-27 - -* Thu Apr 25 2013 Matthew Garrett - 0.5.4-15 -- efibootmgr-0.5.4-Work-around-broken-Apple-firmware.patch - Resolves: #873629 -- efibootmgr-0.5.4-Remove-device-path-padding-on-non-Itanium.patch - improve - spec conformance -- efibootmgr-0.5.4-fix-minor-memory-leak.patch - from upstream -- efibootmgr-0.5.4-fix-disk-minor-number-discovery.patch - from upstream -- efibootmgr-0.5.4-make_boot_var-does-not-check-for-failed-status-with-.patch - - from upstream - -* Wed Feb 13 2013 Fedora Release Engineering - 0.5.4-14 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild - -* Wed Jul 18 2012 Fedora Release Engineering - 0.5.4-13 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild - -* Fri Jan 13 2012 Fedora Release Engineering - 0.5.4-12 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild - -* Tue Feb 08 2011 Fedora Release Engineering - 0.5.4-11 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild - -* Wed Dec 01 2010 Peter Jones - 0.5.4-10 -- Add support for bootable devices with 4kB sectors. - -* Wed Apr 14 2010 Peter Jones - 0.5.4-9 -- Make \EFI\redhat\grub.efi the default bootloader - Resolves: rhbz#579665 - -* Fri Jul 24 2009 Fedora Release Engineering - 0.5.4-7 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild - -* Fri Mar 06 2009 Matt Domsch - 0.5.4-6 -- make ExclusiveArch %%{ix86} now that packages are being built as .i586 - -* Tue Feb 24 2009 Fedora Release Engineering - 0.5.4-5 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild - -* Thu Apr 03 2008 Peter Jones - 0.5.4-4 -- Revert changes in -3, they weren't finalized and we don't need - the feature at this time. - -* Thu Mar 06 2008 Peter Jones - 0.5.4-3 -- Add support for setting driver related variables. +* Mon Feb 02 2015 Peter Jones - 0.8.0-5 +- Fix patch merge error from -4 + Resolves: rhbz#1188313 -* Tue Feb 5 2008 Matt Domsch 0.5.4-2 -- rebuild with conflicts/obsoletes matching elilo +* Thu Jan 08 2015 Peter Jones - 0.8.0-4 +- Fix buffer overflow when remove_from_boot_order removes nothing (lennysz) + Resolves: rhbz#1168019 -* Thu Jan 3 2008 Matt Domsch 0.5.4-1 -- split efibootmgr into its own RPM for Fedora/RHEL. +* Wed Oct 15 2014 Peter Jones - 0.8.0-3 +- Don't error when BootOrder is unset and we're trying to add to it. + Related:rhbz#967969 -* Thu Aug 24 2004 Matt Domsch -- new home linux.dell.com +* Wed Sep 10 2014 Peter Jones - 0.8.0-2 +- Fix some covscan related errors. + Related: rhbz#1129435 -* Fri May 18 2001 Matt Domsch -- See doc/ChangeLog +* Fri Sep 05 2014 Peter Jones - 0.8.0-1 +- Rebase to 0.8.0 + Resolves: rhbz#1129435