OSDN Git Service

android-x86/external-efivar.git
6 years agoAndroid: inital porting of libefivar nougat-x86 android-x86-7.1-r1 android-x86-7.1-r2 android-x86-7.1-r3 android-x86-7.1-r4 android-x86-7.1-r5
Chih-Wei Huang [Fri, 12 Jan 2018 03:31:18 +0000 (11:31 +0800)]
Android: inital porting of libefivar

The static library is linked by efibootmgr.

6 years agomakeguids: use builtins for bswap() functions.
Peter Jones [Mon, 4 Dec 2017 22:46:13 +0000 (17:46 -0500)]
makeguids: use builtins for bswap() functions.

6 years agomakeguids: Ensure compatibility with other libcs
A. Wilcox [Sat, 19 Aug 2017 01:36:03 +0000 (20:36 -0500)]
makeguids: Ensure compatibility with other libcs

The musl libc does not provide __bswap_constant_XX.
If <endian.h> does not provide these macros, use our own.

This fixes issue #84.

6 years agoAdd NVDIMM-P support
Peter Jones [Mon, 4 Dec 2017 22:27:57 +0000 (17:27 -0500)]
Add NVDIMM-P support

6 years agobetter error reports in linux and creator code
Peter Jones [Mon, 4 Dec 2017 22:24:46 +0000 (17:24 -0500)]
better error reports in linux and creator code

6 years agofixup for 3a2a35f638e
Peter Jones [Mon, 4 Dec 2017 22:23:17 +0000 (17:23 -0500)]
fixup for 3a2a35f638e

6 years agoadd protocol guids list
Peter Jones [Mon, 4 Dec 2017 20:02:26 +0000 (15:02 -0500)]
add protocol guids list

6 years agoAdd the external management mechanism guid
Peter Jones [Mon, 4 Dec 2017 15:47:12 +0000 (10:47 -0500)]
Add the external management mechanism guid

6 years agoefivarfs_set_variable(): don't test access before creating variables.
Peter Jones [Tue, 26 Sep 2017 18:05:02 +0000 (14:05 -0400)]
efivarfs_set_variable(): don't test access before creating variables.

Coverity, possibly correctly (though it's hard to see what the resulting
problem would be in this case), believes checking access(path, F_OK)
before doing open(path, ...) is a TOCTOU error.  And it arguably is,
except you have to be root to do this and we're operating entirely in
sysfs, so... hard to see how you could race it or what you could gain.
Maybe something at a higher level can be convinced to race stupidly if
you're calling libefivar.  I dunno.

Anyway, attempt to fix it.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoWork around coverity being stupid (CID 182336/REVERSE_INULL)
Peter Jones [Tue, 26 Sep 2017 17:42:16 +0000 (13:42 -0400)]
Work around coverity being stupid (CID 182336/REVERSE_INULL)

Coverity *really* doesn't like testing a string that's been previously
dereferenced, because they believe programs are written once and nothing
ever changes, and they don't believe common error paths should plan for
that to happen.

Thus, if you do:

int
foo(void)
{
int ret = -1, rc;
char *path = NULL;

rc = asprintf(&path, "foo");
if (rc < 0)
return -1; // because this is return, not goto err ...

// lots of stuff ...
if (rc < 0)
goto err; // ... and this is goto err ...

// stuff ...
ret = 0;
err:
if (path) // ... CID 182336 (REVERSE_INULL) triggers here
free(path);
return ret;
}

Even though this is perfectly reasonable code that does not contain any
actual bugs, coverity's REVERSE_INULL check complains about the test on
path.  This isn't a complaint about the code - it's an error message
about coverity's inability to infer why you've done it.  And why you've
done it is so that if the code above changes, the error path doesn't
suddenly become unsafe.

So change the error path usage so that it will also jump to the common
error path, which is completely unnecessary, when path could be NULL.

Yes, this is stupid.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefivar: prepare_data(): check for invalid filename.
Peter Jones [Tue, 26 Sep 2017 17:37:59 +0000 (13:37 -0400)]
efivar: prepare_data(): check for invalid filename.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake a checker for coverity being installed
Peter Jones [Tue, 26 Sep 2017 17:21:59 +0000 (13:21 -0400)]
Make a checker for coverity being installed

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoRemove popt-devel from BuildRequires in the spec file.
David Cantrell [Fri, 22 Sep 2017 16:51:55 +0000 (12:51 -0400)]
Remove popt-devel from BuildRequires in the spec file.

Signed-off-by: David Cantrell <david.l.cantrell@gmail.com>
6 years agoRemove PKGS=popt from src/Makefile
David Cantrell [Fri, 22 Sep 2017 16:52:31 +0000 (12:52 -0400)]
Remove PKGS=popt from src/Makefile

Signed-off-by: David Cantrell <david.l.cantrell@gmail.com>
6 years agoReplace popt usage with getopt_long in efivar.c.
David Cantrell [Tue, 26 Sep 2017 13:50:50 +0000 (09:50 -0400)]
Replace popt usage with getopt_long in efivar.c.

efivar does not make use of popt in a way that really requires the
dependency.  Since this is a low level system utility, it's possible
some system builders want to reduce redundant libraries they need to
build and install.  popt is arguably redundant with getopt_long.  It's
possible to just drop long option handling entirely so it works with
plain old getopt.  The intent with this patch was to provide the same
command line options but just using what the C library provides rather
than popt.

The attributes variable in main() has also been changed to a uint32_t
size and sign consistency with its usage in edit_variable().

Signed-off-by: David Cantrell <david.l.cantrell@gmail.com>
6 years agotest: Fix efivar.h location
rtlanceroad [Wed, 13 Sep 2017 10:10:33 +0000 (18:10 +0800)]
test: Fix efivar.h location

When other bits of the source got fixed to use a different include path
for efivars, the test directory did not.

6 years agoRevert "Enable C11 mode" (d7e8e4c6) and do it the right way.
Peter Jones [Tue, 26 Sep 2017 17:01:13 +0000 (13:01 -0400)]
Revert "Enable C11 mode" (d7e8e4c6) and do it the right way.

This reverts commit d7e8e4c646ff02ec7e308998de5f2318d6607dbc.

We already have -std=gnu11 in gcc.specs, we just need it on the clang
side as well, so put it there.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake pkg-config test if CROSS_COMPILE applies...
Peter Jones [Mon, 13 Feb 2017 22:16:28 +0000 (17:16 -0500)]
Make pkg-config test if CROSS_COMPILE applies...

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake.defaults: honor COMPILER to make CI easier.
Peter Jones [Mon, 13 Feb 2017 21:48:31 +0000 (16:48 -0500)]
Make.defaults: honor COMPILER to make CI easier.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoadd some travis CI bits here to see if it works
Peter Jones [Fri, 10 Feb 2017 22:10:50 +0000 (17:10 -0500)]
add some travis CI bits here to see if it works

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agomake: improve 'clean' target
Peter Jones [Mon, 25 Sep 2017 18:50:38 +0000 (14:50 -0400)]
make: improve 'clean' target

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake format_ucs2() not use a variable-length array.
Peter Jones [Mon, 25 Sep 2017 16:20:04 +0000 (12:20 -0400)]
Make format_ucs2() not use a variable-length array.

Coverity complains (during the build, as a "recoverable" error):

"dp.h", line 134: warning #1234: a variable-length array is not allowed inside
          of a statement expression
                uint16_t _ucs2buf[(len)];                               \
                         ^

So don't do that.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoUse fwupdate's Make.coverity instead of implementing it inline.
Peter Jones [Mon, 25 Sep 2017 16:08:09 +0000 (12:08 -0400)]
Use fwupdate's Make.coverity instead of implementing it inline.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoEnable C11 mode
Gabriel Majeri [Sun, 24 Sep 2017 12:20:51 +0000 (15:20 +0300)]
Enable C11 mode

6 years agoDo not warn on taking address of packed member
Gabriel Majeri [Sun, 24 Sep 2017 11:59:50 +0000 (14:59 +0300)]
Do not warn on taking address of packed member

6 years agoCast port to 16-bit integer
Gabriel Majeri [Sun, 24 Sep 2017 11:59:27 +0000 (14:59 +0300)]
Cast port to 16-bit integer

6 years agoUse `__typeof__` instead of `typeof`
Gabriel Majeri [Sun, 24 Sep 2017 11:59:13 +0000 (14:59 +0300)]
Use `__typeof__` instead of `typeof`

6 years agoImprove __nonnull__ usage on clang
Gabriel Majeri [Sun, 24 Sep 2017 11:24:08 +0000 (14:24 +0300)]
Improve __nonnull__ usage on clang

On gcc, we use the pragma "-Wnonnull-compare" to avoid GCC's complaints
of checking for NULL on a function marked with __nonnull__.  This adds
clang's -Wpointer-bool-conversion to avoid the same kind of thing there.

6 years agoFix const to non-const pointer cast
Gabriel Majeri [Sun, 24 Sep 2017 11:13:29 +0000 (14:13 +0300)]
Fix const to non-const pointer cast

6 years agoReplace zero-length arrays with C99 flexible array member
Gabriel Majeri [Sun, 24 Sep 2017 11:08:05 +0000 (14:08 +0300)]
Replace zero-length arrays with C99 flexible array member

6 years agoDisable the __artificial__ attribute on Clang
Gabriel Majeri [Sun, 24 Sep 2017 11:04:34 +0000 (14:04 +0300)]
Disable the __artificial__ attribute on Clang

6 years agogeneric_append_variable(): only try to create if errno was ENOENT
Peter Jones [Sat, 8 Jul 2017 16:56:10 +0000 (12:56 -0400)]
generic_append_variable(): only try to create if errno was ENOENT

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAllow abigail to ignore a few more things.
Peter Jones [Tue, 12 Sep 2017 20:32:50 +0000 (16:32 -0400)]
Allow abigail to ignore a few more things.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake efi_guid_ux_capsule actually work.
Peter Jones [Tue, 12 Sep 2017 14:45:31 +0000 (10:45 -0400)]
Make efi_guid_ux_capsule actually work.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoUpdate efivar.spec.in
Peter Jones [Tue, 12 Sep 2017 14:21:10 +0000 (10:21 -0400)]
Update efivar.spec.in

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoBump version to 32
Peter Jones [Tue, 12 Sep 2017 13:59:40 +0000 (09:59 -0400)]
Bump version to 32

- lots of coverity fixes; mostly leaked memory and fds and the like
- fix sysfs pci path formats
- handle device paths for dns, nfit, bluetooth, wifi, emmc, btle.
- improved abi checking on releases
- Fix failures on EDIT_WRITE in edit_variable() when the variable doesn't
  exist
- Add efi_guid_ux_capsule_guid to our guids

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake "make archive" update the version number and do the ABI check right.
Peter Jones [Mon, 11 Sep 2017 20:58:00 +0000 (16:58 -0400)]
Make "make archive" update the version number and do the ABI check right.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoImprove libabigail support a bit.
Peter Jones [Mon, 11 Sep 2017 19:25:40 +0000 (15:25 -0400)]
Improve libabigail support a bit.

This does a couple of things:
- makes sure we're using --headers-dir with abidw and --headers-dir2
  with abidiff
- ignores additions to the efidp_data type
- Makes the abidw commit amend onto the "bump version" one.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd the localized text image guid.
Peter Jones [Mon, 11 Sep 2017 17:37:42 +0000 (13:37 -0400)]
Add the localized text image guid.

As documented here: https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/boot-screen-components

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd a syntastic config for vim
Peter Jones [Mon, 11 Sep 2017 17:32:36 +0000 (13:32 -0400)]
Add a syntastic config for vim

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd a formatter for Dns() device types.
Peter Jones [Fri, 21 Jul 2017 13:53:11 +0000 (09:53 -0400)]
Add a formatter for Dns() device types.

This re-organizes the IPv4 and IPv6 formatters so they can be used to
print Dns() entries, and then uses them to do that.

Maybe?  Not sure if I've got endianness right.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agomost 2.7 types, but not dns or nfit
Peter Jones [Fri, 21 Jul 2017 13:53:11 +0000 (09:53 -0400)]
most 2.7 types, but not dns or nfit

6 years agoAdd NvDimm _ADR encoder/decoder.
Peter Jones [Thu, 20 Jul 2017 18:05:19 +0000 (14:05 -0400)]
Add NvDimm _ADR encoder/decoder.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefivar-dp.h: add EFIDP_EFI_ACPI_ID() and related bits.
Peter Jones [Thu, 20 Jul 2017 18:01:24 +0000 (14:01 -0400)]
efivar-dp.h: add EFIDP_EFI_ACPI_ID() and related bits.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefivar-dp.h: Add a bunch of UEFI 2.7 messaging device path types.
Peter Jones [Thu, 20 Jul 2017 18:04:51 +0000 (14:04 -0400)]
efivar-dp.h: Add a bunch of UEFI 2.7 messaging device path types.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoformat_hex_helper: add the ability to include separators.
Peter Jones [Thu, 20 Jul 2017 18:06:22 +0000 (14:06 -0400)]
format_hex_helper: add the ability to include separators.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake our -I path not include efivar/
Peter Jones [Fri, 21 Jul 2017 13:52:22 +0000 (09:52 -0400)]
Make our -I path not include efivar/

This allows vim's syntax checker to find the include files correctly,
which is nice while working on it.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefivar-dp.h: fix argument names in efidp_encode_acpi_display_adr
Peter Jones [Thu, 20 Jul 2017 18:00:04 +0000 (14:00 -0400)]
efivar-dp.h: fix argument names in efidp_encode_acpi_display_adr

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolinux.c: fix sysfs pci path format specifiers
Peter Jones [Fri, 21 Jul 2017 13:04:42 +0000 (09:04 -0400)]
linux.c: fix sysfs pci path format specifiers

%4x sometimes introduces spaces; this should use %04hx for root_domain
and %02hhx for root_bus everywhere.

Resolves github issue #83.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoedit_variable(): don't fail with EDIT_WRITE on non-existing variables.
Peter Jones [Thu, 20 Jul 2017 18:08:14 +0000 (14:08 -0400)]
edit_variable(): don't fail with EDIT_WRITE on non-existing variables.

If we're writing a variable, not being able to read it first is fine.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefivar-dp.h: Make __attribute__((__packed__)) into an easier to type macro.
Peter Jones [Thu, 20 Jul 2017 17:59:15 +0000 (13:59 -0400)]
efivar-dp.h: Make __attribute__((__packed__)) into an easier to type macro.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd coverity build+upload make targets
Peter Jones [Tue, 9 May 2017 15:40:56 +0000 (11:40 -0400)]
Add coverity build+upload make targets

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolinux.c: fix a pile of sscanf(NULL, ...) possibilities.
Peter Jones [Tue, 9 May 2017 20:33:27 +0000 (16:33 -0400)]
linux.c: fix a pile of sscanf(NULL, ...) possibilities.

Covscan apparently can't figure out that rc!=error == buf!=NULL.

None of these should ever actually happen, because we're checking for
the error cases from the functions that should fill them in, but hey,
belt and suspenders.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefi_generate_file_device_path(): make all error paths use "goto err;"
Peter Jones [Tue, 9 May 2017 20:32:09 +0000 (16:32 -0400)]
efi_generate_file_device_path(): make all error paths use "goto err;"

Honestly I'm just trying to shut coverity up about checking
child_devpath for NULL-ness twice on the other two error paths.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoefi_loadopt_create(): avoid NULL dereference
Peter Jones [Tue, 9 May 2017 19:34:08 +0000 (15:34 -0400)]
efi_loadopt_create(): avoid NULL dereference

covscan rightly points out that dp is allowed to be NULL (and so is
buf), so we can't pass those in to memcpy() in those cases.

So don't.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoSimplify efidp_append_node() even more.
Peter Jones [Tue, 9 May 2017 19:15:55 +0000 (15:15 -0400)]
Simplify efidp_append_node() even more.

Covscan rightly notices that now we've got enough tests on dp and dn
that some of them are provably dead code.

So take a bunch out.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agogpt: try to avoid trusting unverified partition table data.
Peter Jones [Tue, 9 May 2017 18:20:13 +0000 (14:20 -0400)]
gpt: try to avoid trusting unverified partition table data.

Covscan complains thusly:
 4. efivar-31/src/gpt.c:338: tainted_data_return: Function "alloc_read_gpt_header" returns tainted data.
 7. efivar-31/src/gpt.c:311:2: tainted_data_argument: Function "read_lba" taints argument "gpt".
12. efivar-31/src/gpt.c:245:2: tainted_data_argument: Calling function "read" taints parameter "*iobuf". [Note: The source code implementation of the function has been overridden by a builtin model.]
13. efivar-31/src/gpt.c:246:2: tainted_data_transitive: "memcpy" taints argument "buffer" because argument "iobuf" is tainted. [Note: The source code implementation of the function has been overridden by a builtin model.]
16. efivar-31/src/gpt.c:316:2: return_tainted_data: Returning tainted variable "gpt".
17. efivar-31/src/gpt.c:338: var_assign: Assigning: "*gpt" = "alloc_read_gpt_header", which taints "*gpt".
26. efivar-31/src/gpt.c:382: tainted_data: Passing tainted variable "(*gpt)->num_partition_entries" to a tainted sink.
27. efivar-31/src/gpt.c:272:15: var_assign_alias: Assigning: "count" = "(__u32)(__le32)gpt->num_partition_entries * (__u32)(__le32)gpt->sizeof_partition_entry". Both are now tainted.
30. efivar-31/src/gpt.c:278:2: tainted_data_sink_lv_call: Passing tainted variable "count" to tainted data sink "malloc".

Hopefully this patch validates num_partition_entries and
sizeof_partition_entry well enough...

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agodp.h: Try to make covscan believe format() is checking its bounds.
Peter Jones [Mon, 1 May 2017 19:59:09 +0000 (15:59 -0400)]
dp.h: Try to make covscan believe format() is checking its bounds.

covscan doesn't grok that size and off wind up being proxies for buf's
NULL check.  Hilarity ensues.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefivar main(): explain efi_well_known_guids to the compiler better.
Peter Jones [Mon, 1 May 2017 19:34:28 +0000 (15:34 -0400)]
efivar main(): explain efi_well_known_guids to the compiler better.

Covscan doesn't quite understand that this _is_ an array, so make it
look even more like one.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agocalls to sysfs_readlink(): check linkbuf for NULLness.
Peter Jones [Mon, 1 May 2017 19:21:13 +0000 (15:21 -0400)]
calls to sysfs_readlink(): check linkbuf for NULLness.

If linkbuf were NULL, sysfs_readlink() would have returned an error, but
covscan can't figure that out, so it thinks linkbuf might be NULL.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_loadopt_args_from_file(): make sure buf is only NULL if size is.
Peter Jones [Mon, 1 May 2017 19:19:18 +0000 (15:19 -0400)]
efi_loadopt_args_from_file(): make sure buf is only NULL if size is.

This avoids passing NULL to fread().

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoshow_errors(): make the useful part here not be dead code.
Peter Jones [Mon, 1 May 2017 19:18:05 +0000 (15:18 -0400)]
show_errors(): make the useful part here not be dead code.

Woops.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefidp_duplicate_extra(): error if our allocation is too small.
Peter Jones [Mon, 1 May 2017 19:14:33 +0000 (15:14 -0400)]
efidp_duplicate_extra(): error if our allocation is too small.

Covscan believes we might pass 0 to calloc(), though I suspect this is
because it doesn't fully grok add().

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_loadopt_create(): check buf for NULLness.
Peter Jones [Mon, 1 May 2017 19:04:24 +0000 (15:04 -0400)]
efi_loadopt_create(): check buf for NULLness.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_variable_import(): constrain our inputs better.
Peter Jones [Mon, 1 May 2017 19:02:27 +0000 (15:02 -0400)]
efi_variable_import(): constrain our inputs better.

efi_variable_import() could plausibly pass NULL to memcpy() if buf is 0
and size is < 0, though that should never be the case.  Make the input
checking return EINVAL if that's the case.

Found by Covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agomakeguids: free our input buffer.
Peter Jones [Mon, 1 May 2017 18:59:57 +0000 (14:59 -0400)]
makeguids: free our input buffer.

Covscan noticed this, but didn't notice that this is a short lived
program that just parses some tables during the build.  It *sooo*
doesn't matter.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_variable_import(): make sure var.data_size is set.
Peter Jones [Mon, 1 May 2017 18:56:53 +0000 (14:56 -0400)]
efi_variable_import(): make sure var.data_size is set.

Covscan noticed that var.data_size isn't set when we memcpy the
structure.  It should be set.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefidp_append_path(): error check the right variable.
Peter Jones [Mon, 1 May 2017 18:54:15 +0000 (14:54 -0400)]
efidp_append_path(): error check the right variable.

We do lsz=efidp_size(dp); rsz=efidp_size(dn); and then we error check
lsz twice.  One should be rsz.

We also actually do the whole thing with lsz twice anyway, and fail to
check that dp isn't NULL first.

We're also not error checking that the buffer from our addition is
actually large enough to hold something meaningful.  So do that too.

None of that is right, so fix it.

Covscan completely failed to notice this, but complained about something
irrelevant later on in the code that's a result.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_variable_import(): fix memory leak on failure path.
Peter Jones [Mon, 1 May 2017 18:52:48 +0000 (14:52 -0400)]
efi_variable_import(): fix memory leak on failure path.

When one of our allocations fails, we leak the other one.  Woops.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_va_generate_file_device_path_from_esp(): handle errors better.
Peter Jones [Mon, 1 May 2017 18:48:49 +0000 (14:48 -0400)]
efi_va_generate_file_device_path_from_esp(): handle errors better.

When efi_va_generate_file_device_path_from_esp() gets an error from
efidp_make_edd10() or make_blockdev_path(), it fails to close the file
descriptor it uses to do ioctl() against the disk.  So make it use the
common error path for those as well.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_generate_file_device_path(): fix one error case's free path.
Peter Jones [Mon, 1 May 2017 18:46:37 +0000 (14:46 -0400)]
efi_generate_file_device_path(): fix one error case's free path.

When efi_generate_file_device_path() gets an error from
find_parent_devpath(), it currently just returns an error, rather than
freeing up its intermediate resources.  So free them.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agogpt_disk_get_partition_info(): free our allocations on the error path.
Peter Jones [Mon, 1 May 2017 18:44:43 +0000 (14:44 -0400)]
gpt_disk_get_partition_info(): free our allocations on the error path.

When gpt_disk_get_partition_info() discovers that a partition is
invalid, it returns error, but it forgets to free its allocations.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agomake_mac_path(): fix leaked file descriptor.
Peter Jones [Mon, 1 May 2017 18:42:25 +0000 (14:42 -0400)]
make_mac_path(): fix leaked file descriptor.

When make_mac_path() gets an error from efidp_make_mac_addr(), it fails
to close the file descriptor to the network device.  So close it.  Also
ensure that the ifrn_name field is NUL terminated.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefi_loadopt_args_from_file(): fix leaked file descriptor.
Peter Jones [Mon, 1 May 2017 18:40:26 +0000 (14:40 -0400)]
efi_loadopt_args_from_file(): fix leaked file descriptor.

In the case where we're just trying to figure out the file's size, we're
failing to close the file.  So close it.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoUpdate .abixml files
Peter Jones [Tue, 7 Mar 2017 16:16:25 +0000 (11:16 -0500)]
Update .abixml files

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoBump version to 31
Peter Jones [Mon, 6 Feb 2017 19:52:58 +0000 (14:52 -0500)]
Bump version to 31

- Work around NVMe EUI sysfs change
- Provide some oldish version strings we should have kept.
- lots of overflow checking on our pointer math in dp parsing
- fix major/minor device number handling in the linux code
- Do better formatting checks for MBR partitions
- Fixes for gcc 7

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agolibefivar: drop conditional include of sys/sysmacros.h
Raymund Will [Tue, 21 Feb 2017 14:55:43 +0000 (15:55 +0100)]
libefivar: drop conditional include of sys/sysmacros.h

This reverts commit c5685d8d as it has been obsoleted by commit 3ad5aab6.

Signed-off-by: Raymund Will <rw@suse.com>
7 years agoMake 'make test-archive' do abicheck
Peter Jones [Tue, 14 Feb 2017 16:42:15 +0000 (11:42 -0500)]
Make 'make test-archive' do abicheck

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoMake ACPI _ADR encoding/decoding more useful.
Peter Jones [Wed, 1 Feb 2017 19:28:14 +0000 (14:28 -0500)]
Make ACPI _ADR encoding/decoding more useful.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoAdd an abicheck makefile rule
Peter Jones [Mon, 13 Feb 2017 16:05:43 +0000 (11:05 -0500)]
Add an abicheck makefile rule

This adds an abicheck makefile rule, and puts it in the "make archive"
path.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoAdd some .abixml files
Peter Jones [Mon, 13 Feb 2017 16:35:02 +0000 (11:35 -0500)]
Add some .abixml files

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoMake a target to update .abixml files.
Peter Jones [Mon, 13 Feb 2017 16:05:25 +0000 (11:05 -0500)]
Make a target to update .abixml files.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoAdd the ABI tracker to the readme
Peter Jones [Mon, 6 Feb 2017 21:46:49 +0000 (16:46 -0500)]
Add the ABI tracker to the readme

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoDon't build static by default.
Peter Jones [Mon, 6 Feb 2017 21:27:54 +0000 (16:27 -0500)]
Don't build static by default.

Since lots of distros don't ship static libraries, it's better not to do
this by default.  This also adds "make static" as a top-level build
target.

This fixes github issue #72.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoDon't call mode optional in the man page any more.
Peter Jones [Mon, 6 Feb 2017 21:00:54 +0000 (16:00 -0500)]
Don't call mode optional in the man page any more.

Since it's such a pain to keep optional mode working and we've taken out
the API declaration that makes it possible to use in new code, take it
out of the docs as well.

This fixes github issue #73

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoAlso provide LIBEFIVAR_1.2X even though nothing really uses it.
Peter Jones [Mon, 6 Feb 2017 20:43:51 +0000 (15:43 -0500)]
Also provide LIBEFIVAR_1.2X even though nothing really uses it.

We've exported these names before, so we still have to have them.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoMake AcpiAdr() device paths format correctly for display.
Peter Jones [Thu, 27 Oct 2016 13:14:18 +0000 (09:14 -0400)]
Make AcpiAdr() device paths format correctly for display.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoUse -z muldefs to avoid the multiple definitions bug without -flto
Peter Jones [Thu, 27 Oct 2016 13:19:18 +0000 (09:19 -0400)]
Use -z muldefs to avoid the multiple definitions bug without -flto

This fixes github issue #64

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoMake sure we define the version for new symbols recently added...
Peter Jones [Mon, 6 Feb 2017 20:12:08 +0000 (15:12 -0500)]
Make sure we define the version for new symbols recently added...

Because symbol versioning is a nightmare, this tool has shown that we've
got an error where we changed the version on some things by accident:

https://abi-laboratory.pro/tracker/compat_report/efivar/29/30/e3de7/abi_compat_report.html

Make those keep the 1.30 version forever.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoNew gcc version, new way symbol versioning breaks.
Peter Jones [Mon, 6 Feb 2017 19:41:58 +0000 (14:41 -0500)]
New gcc version, new way symbol versioning breaks.

Apparently I get to redo this every time there's a compiler release.
Yaaaaaay.

Anyway, the current method is to define the two compat things from the
land before time as @libefivar.so.0 symbols and list them there in the
link map.  Then we have the real one defined with another name, and set
as efi_set_variable@@LIBEFIVAR_0.24.  Then to make there actually be a
efi_set_variable symbol to link against, we create it as a weak alias.

This is all completely absurd.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoRemove some extra "const" that gcc complains about.
Peter Jones [Mon, 6 Feb 2017 19:28:19 +0000 (14:28 -0500)]
Remove some extra "const" that gcc complains about.

One of these days I'll get these right.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoFix some allocation bounds checking gcc 7.x finds sometimes.
Peter Jones [Mon, 6 Feb 2017 19:17:09 +0000 (14:17 -0500)]
Fix some allocation bounds checking gcc 7.x finds sometimes.

gcc 7.0.1 has -Walloca-larger-than=N and -Walloc-size-larger-than=N
flags that -O2 enables now, and they try to bounds check arguments to
alloca() and malloc().

Unfortunately they have horrible error messages, so you get:

dp-message.c: In function ‘_format_message_dn’:
dp-message.c:422:9: error: argument 1 range [922337203685477580918446744073709551615] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
   addr0 = alloca(sz+1);
         ^
dp-message.c:422:9: note: in a call to built-in allocation function ‘__builtin_alloca’

When what it means is:

 Check for error you nitwit.  Now I'm going to tell you a pile of math
 we did that isn't useful to you at all.

And also:

dp-message.c:466:3: error: argument 1 value ‘18446744073709551606’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
   format_ucs2(buf, size, off, "UsbWwid",
   ^
dp-message.c:466:3: note: in a call to built-in allocation function ‘__builtin_alloca_with_align’
dp-message.c:466:3: error: ‘memset’: specified size 18446744073709551606 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
dp-message.c:466:3: error: ‘memcpy’: specified size 18446744073709551604 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

Which actually means:

 You accidentally made the predicating check for bounds be against a
 signed value Now I'm going to tell you a pile of useless data about
 where you later used the result instead of telling you about the
 problem.

Anyway, this fixes it.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoformat_media_dn: Fix formatting of disk signature for MBR partitions
Dwayne Litzenberger [Thu, 19 Jan 2017 00:35:46 +0000 (16:35 -0800)]
format_media_dn: Fix formatting of disk signature for MBR partitions

The previous logic sign-extended the least-significant byte of the disk
signature and returned a decimal number prefixed with "0x", producing
nonsense like this:

    # blkid -o value -s PTUUID /dev/sdb
    927a7490
    # efibootmgr -v | grep debian
    Boot0002* debian HD(3,MBR,0x4294967184,0xe89c0000,0x100000)/File(\EFI\debian\grubx64.efi)
    # python -c 'print hex(4294967184)'
    0xffffff90

With this change, it works properly:

    Boot0002* debian HD(3,MBR,0x927a7490,0xe89c0000,0x100000)/File(\EFI\debian\grubx64.efi)

Signed-off-by: Dwayne Litzenberger <dlitz@dlitz.net>
7 years agolinux: fix device major/minor handling.
Nicolas George [Sun, 13 Nov 2016 18:04:30 +0000 (19:04 +0100)]
linux: fix device major/minor handling.

The current code fails when minor >= 256 because the higher
bits are kept in major.

Fix: Debian bug #844237

7 years ago_format_message_dn(): fix the check for a label in the EFIDP_MSG_VENDOR case.
Peter Jones [Wed, 19 Oct 2016 18:59:35 +0000 (14:59 -0400)]
_format_message_dn(): fix the check for a label in the EFIDP_MSG_VENDOR case.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefidp_is_multiinstance(): check for efidp_next_node() == 0 in our iter
Peter Jones [Wed, 19 Oct 2016 18:18:27 +0000 (14:18 -0400)]
efidp_is_multiinstance(): check for efidp_next_node() == 0 in our iter

GCC doesn't seem to want to believe that the NULL and length tests in
in efidp_is_multiinstance()->efidp_next_node()->efidp_node_size()
actually catches things, Possibly because it wouldn't be acted on until
the next iteration through the loop.   So check that case explicitly in
efidp_is_multiinstance().  Also forcibly set 'next' to NULL, to ensure
efidp_next_node() will catch it.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoefidp_*(): make everything that does pointer math check for overflow.
Peter Jones [Wed, 19 Oct 2016 18:18:45 +0000 (14:18 -0400)]
efidp_*(): make everything that does pointer math check for overflow.

None of these overflows will really happen in the real world, because
they depend on the address of the next-to-last efidp_header being 4
bytes from the top of memory, but check them anyway.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agolib*: provide LIBEFIVAR_1.28 etc.
Peter Jones [Wed, 28 Sep 2016 13:28:24 +0000 (09:28 -0400)]
lib*: provide LIBEFIVAR_1.28 etc.

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoCheck for the NVMe EUI in the base sysfs dir for the device as well
Peter Jones [Mon, 17 Oct 2016 14:04:48 +0000 (10:04 -0400)]
Check for the NVMe EUI in the base sysfs dir for the device as well

Kernel commit 779ff75617099f4defe14e20443b95019a4c5ae8 moves the NVMe
attributes from being under nvme0n1/device/* to just being in the
nvme0n1/ directory.  So now we get to check for both things.  Thanks,
sysfs.

This resolves github issue #65
This resolves https://github.com/rhinstaller/efibootmgr/issues/48

Signed-off-by: Peter Jones <pjones@redhat.com>
7 years agoBump version to 30
Peter Jones [Tue, 27 Sep 2016 18:21:13 +0000 (14:21 -0400)]
Bump version to 30

- Fix efidp_*() functions with __pure__ that break with some optimizations
- Fix NVMe EUI parsing.

Signed-off-by: Peter Jones <pjones@redhat.com>