Update to 0.10.0

- Make -o parameter validation work better and be more informative
- Better exit values
- Fix a segfault with appending ascii arguments.

Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
Peter Jones 2014-10-20 12:27:13 -04:00
parent 2911475b8d
commit 347764f414
3 changed files with 8 additions and 237 deletions

View File

@ -1,234 +0,0 @@
From 9885893340146150df885f091bf17db840619154 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 14 Oct 2014 15:09:56 -0400
Subject: [PATCH] Make a few more return paths print some modicum of error
message.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/efibootmgr/efibootmgr.c | 16 ++++++++---
src/lib/efi.c | 68 +++++++++++++++++++++++++++++----------------
2 files changed, 56 insertions(+), 28 deletions(-)
diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c
index 01c1505..5f09b0b 100644
--- a/src/efibootmgr/efibootmgr.c
+++ b/src/efibootmgr/efibootmgr.c
@@ -242,16 +242,20 @@ make_boot_var(list_t *boot_list)
free_number = opts.bootnum;
}
- if (free_number == -1)
+ if (free_number == -1) {
+ fprintf(stderr, "efibootmgr: no available boot variables\n");
return NULL;
+ }
/* Create a new efi_variable_t object
and populate it.
*/
boot = calloc(1, sizeof(*boot));
- if (!boot)
+ if (!boot) {
+ fprintf(stderr, "efibootmgr: %m\n");
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 +264,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) {
+ fprintf(stderr, "efibootmgr: %m\n");
goto err_boot_entry;
+ }
boot->attributes = EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS;
@@ -272,8 +278,10 @@ 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) {
+ fprintf(stderr, "Could not set variable %s: %m\n", boot->name);
free(boot->name);
+ }
if (boot->data)
free(boot->data);
free(boot);
diff --git a/src/lib/efi.c b/src/lib/efi.c
index 7cdc884..4b648fc 100644
--- a/src/lib/efi.c
+++ b/src/lib/efi.c
@@ -724,10 +724,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 +758,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,8 +807,10 @@ 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;
@@ -829,8 +846,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 +890,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 +948,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 +969,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 +978,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;
}
--
1.9.3

View File

@ -1,6 +1,6 @@
Summary: EFI Boot Manager
Name: efibootmgr
Version: 0.9.0
Version: 0.10.0
Release: 1%{?dist}
Group: System Environment/Base
License: GPLv2+
@ -17,7 +17,6 @@ Conflicts: elilo < 3.6-6
Obsoletes: elilo < 3.6-6
Source0: https://github.com/vathpela/%{name}/releases/download/%{name}-%{version}/%{name}-%{version}.tar.bz2
Patch0: 0001-Make-a-few-more-return-paths-print-some-modicum-of-e.patch
%description
%{name} displays and allows the user to edit the Intel Extensible
@ -54,6 +53,12 @@ rm -rf %{buildroot}
%doc README INSTALL COPYING
%changelog
* Mon Oct 20 2014 Peter Jones <pjones@redhat.com> - 0.10.0-1
- Update to 0.10.0
- Make -o parameter validation work better and be more informative
- Better exit values
- Fix a segfault with appending ascii arguments.
* Tue Oct 14 2014 Peter Jones <pjones@redhat.com> - 0.9.0-1
- Update to 0.9.0

View File

@ -1 +1 @@
cee2d8fd87cdc2ea4839455f00e38248 efibootmgr-0.9.0.tar.bz2
9efeb2e0155d01a6bc5218f5823b22bb efibootmgr-0.10.0.tar.bz2