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)
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;
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);
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;
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;
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 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;
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)
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;
}
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;
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;
}