Fix a bad allocation size.

Covscan found this.

Signed-off-by: Peter Jones <pjones@redhat.com>
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 <pjones@redhat.com>
Don't leak our socket's fd when determining network info.

Covscan again.

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix another leaked fd.

Covscan some more.

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix some minor memory leaks.

Well, one and not really another.  Covscan is /almost/ a great tool.

Signed-off-by: Peter Jones <pjones@redhat.com>
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 <pjones@redhat.com>
Fix an error path not checking the return right in make_linux_load_option

Covscan once again.

Signed-off-by: Peter Jones <pjones@redhat.com>
Try to avoid covscan freaking out about sscanf with %n.

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 <pjones@redhat.com>
Get rid of an invalid comparison.

Covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
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 <pjones@redhat.com>
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 <pjones@redhat.com>
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 <pjones@redhat.com>
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 <pjones@redhat.com>
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 <pjones@redhat.com>
Check malloc() return.

Covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
Check open()s return correctly.

Covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
Check lseek() for errors.

Covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
Don't leak our partition table structures.

Covscan once more.

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