Free mok lists we've allocated in our error paths.

Coverity says they're leaking, and it's right, though I suspect we just
exit anyway.

Signed-off-by: Peter Jones <pjones@redhat.com>
Don't close file descriptors < 0.

Coverity complains, though you'll just get EBADFD.

Signed-off-by: Peter Jones <pjones@redhat.com>
Error check reading hash from file.

Coverity noticed that if read() returns error, we're doing string[-1].
We're also only reading some of the file in some cases.  Replaced this
with a proper read loop.

Also we were overruning the string by one byte.

Signed-off-by: Peter Jones <pjones@redhat.com>
Use a read/realloc loop to avoid a race condition on stat()

Coverity says:
 4. shim-0.7/mokutil-0.2.0/src/mokutil.c:1228:toctou – Calling function
 "open(char const *, int, ...)" that uses "key_file" after a check
 function. This can cause a time-of-check, time-of-use race condition.

So with the new code we'll probably get garbage if somebody tries racing
that for some reason, but at least it'll be consistent garbage :)

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix check for string termination that was actually a NULL ptr check...

Coverity says:

 2. shim-0.7/mokutil-0.2.0/src/password-crypt.c:267:check_after_deref –
 Null-checking "tmp" suggests that it may be null, but it has already
 been dereferenced on all paths leading to the check.

And:

 2. shim-0.7/mokutil-0.2.0/src/password-crypt.c:215:check_after_deref –
 Null-checking "tmp" suggests that it may be null, but it has already
 been dereferenced on all paths leading to the check.

But to me it looks like these were supposed to be checking for end-of-string
instead.

Signed-off-by: Peter Jones <pjones@redhat.com>
Make generate_pw_hash() somewhat cleaner.

Coverity needlessly complains:

 2. shim-0.7/mokutil-0.2.0/src/mokutil.c:1322:check_after_deref –
 Null-checking "password" suggests that it may be null, but it has
 already been dereferenced on all paths leading to the check.

While this doesn't really make any difference, the whole ret and
error-path was overkill here, so I got rid of it.

Signed-off-by: Peter Jones <pjones@redhat.com>
Merge pull request #2 from vathpela/master

Several fixes to problems coverity found.