Fix Coverity issues (#1104)

This commit is contained in:
Giovanni 2021-05-05 18:02:04 +02:00 committed by GitHub
parent 88eaf90b9c
commit cf56e35614
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View file

@ -115,7 +115,10 @@ rz_crypto_new_bad:
return NULL;
}
RZ_API struct rz_crypto_t *rz_crypto_free(RzCrypto *cry) {
RZ_API void rz_crypto_free(RzCrypto *cry) {
if (!cry) {
return;
}
if (cry->h && cry->h->fini && !cry->h->fini(cry)) {
RZ_LOG_ERROR("[!] crypto: error terminating '%s' plugin\n", cry->h->name);
}
@ -124,7 +127,6 @@ RZ_API struct rz_crypto_t *rz_crypto_free(RzCrypto *cry) {
free(cry->key);
free(cry->iv);
free(cry);
return NULL;
}
RZ_API bool rz_crypto_use(RzCrypto *cry, const char *algo) {

View file

@ -434,6 +434,7 @@ RZ_API bool rz_msg_digest_final(RzMsgDigest *md) {
if (!mdc->plugin->init(mdc->context)) {
RZ_LOG_ERROR("msg digest: failed to call init for hmac %s opad.\n", mdc->plugin->name);
free(o_pad);
return false;
}
if (!mdc->plugin->update(mdc->context, o_pad, block_size)) {

View file

@ -56,7 +56,7 @@ typedef ut64 RzCryptoSelector;
#ifdef RZ_API
RZ_API int rz_crypto_add(RzCrypto *cry, RzCryptoPlugin *h);
RZ_API RzCrypto *rz_crypto_new(void);
RZ_API RzCrypto *rz_crypto_free(RzCrypto *cry);
RZ_API void rz_crypto_free(RzCrypto *cry);
RZ_API bool rz_crypto_use(RzCrypto *cry, const char *algo);
RZ_API bool rz_crypto_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction);
RZ_API bool rz_crypto_set_iv(RzCrypto *cry, const ut8 *iv, int ivlen);

View file

@ -714,6 +714,7 @@ static void rz_hash_print_digest(RzHashContext *ctx, RzMsgDigest *md, const char
buffer = rz_msg_digest_get_result(md, hname, &len);
value = rz_msg_digest_get_result_string(md, hname, NULL, ctx->little_endian);
if (!value || !buffer) {
free(value);
return;
}

View file

@ -149,7 +149,7 @@ bool test_message_digest_configure() {
bool test_message_digest_hmac_stringified() {
char message[256];
char *result;
char *result = NULL;
bool boolean;
RzMsgDigestSize size;
RzMsgDigest *md = NULL;
@ -174,15 +174,17 @@ bool test_message_digest_hmac_stringified() {
mu_assert_streq(result, hd->expected, message);
free(result);
result = NULL;
rz_msg_digest_free(md);
}
free(result);
mu_end;
}
bool test_message_digest_api_stringified() {
char message[256];
char *result;
char *result = NULL;
bool boolean;
RzMsgDigestSize size;
RzMsgDigest *md = NULL;
@ -207,15 +209,17 @@ bool test_message_digest_api_stringified() {
mu_assert_streq(result, hd->expected, message);
free(result);
result = NULL;
rz_msg_digest_free(md);
}
free(result);
mu_end;
}
bool test_message_digest_small_block_stringified() {
char message[256];
char *result;
char *result = NULL;
RzMsgDigestSize size;
for (size_t i = 0; i < RZ_ARRAY_SIZE(hashes_to_test); ++i) {
@ -224,7 +228,9 @@ bool test_message_digest_small_block_stringified() {
result = rz_msg_digest_calculate_small_block_string(hd->algo, hd->input, hd->input_size, &size, false);
mu_assert_streq(result, hd->expected, message);
free(result);
result = NULL;
}
free(result);
mu_end;
}