Skip to content

Commit

Permalink
swtpm: Add another exit label to avoid gcc -fanalyzer false positive
Browse files Browse the repository at this point in the history
Move existing exit label before the return statement and add another
label that includes the free(filebuffer). This avoids a false positive
by 'gcc -fanalyzer' that seems to think that free(filebuffer)
would double-free filebuffer after filebuffer = realloc(tmp, ..)
failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Oct 5, 2022
1 parent 7d79ecd commit 0438602
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/swtpm/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ key_from_pwdfile_fd(int fd, unsigned char *key, size_t *keylen,
logprintf(STDERR_FILENO,
"Unable to read passphrase: %s\n",
strerror(errno));
goto exit;
goto err_free_buffer;
}
/* EOF ? */
if ((size_t)len < filelen - offset) {
Expand All @@ -345,7 +345,7 @@ key_from_pwdfile_fd(int fd, unsigned char *key, size_t *keylen,
logprintf(STDERR_FILENO,
"Requested %zu bytes for key, only got %zu.\n",
*keylen, sizeof(hashbuf));
goto exit;
goto err_free_buffer;
}
SHA512(filebuffer, len, hashbuf);
memcpy(key, hashbuf, *keylen);
Expand All @@ -356,21 +356,21 @@ key_from_pwdfile_fd(int fd, unsigned char *key, size_t *keylen,
EVP_sha512(), *keylen, key) != 1) {
logprintf(STDERR_FILENO,
"PKCS5_PBKDF2_HMAC with SHA512 failed\n");
goto exit;
goto err_free_buffer;
}
break;
case KDF_IDENTIFIER_UNKNOWN:
logprintf(STDERR_FILENO,
"Unknown KDF\n");
goto exit;
goto err_free_buffer;
}

ret = 0;

exit:

err_free_buffer:
free(filebuffer);

exit:
return ret;
}

Expand Down

0 comments on commit 0438602

Please sign in to comment.