diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-11-21 23:35:09 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-11-27 11:09:21 +0000 |
commit | 3ff56dae29a213110255a30f5085ad290c98d717 (patch) | |
tree | 225cf15c600371d6adbb176a81a41be66fc56eee | |
parent | cac36006ac512db953544e0daff963657589ae9e (diff) | |
download | libgit2-3ff56dae29a213110255a30f5085ad290c98d717.tar.gz |
hash: use GIT_ASSERT
-rw-r--r-- | src/hash/sha1/collisiondetect.c | 6 | ||||
-rw-r--r-- | src/hash/sha1/common_crypto.c | 6 | ||||
-rw-r--r-- | src/hash/sha1/mbedtls.c | 24 | ||||
-rw-r--r-- | src/hash/sha1/openssl.c | 6 | ||||
-rw-r--r-- | src/hash/sha1/win32.c | 21 |
5 files changed, 33 insertions, 30 deletions
diff --git a/src/hash/sha1/collisiondetect.c b/src/hash/sha1/collisiondetect.c index e6a126780..722ebf36f 100644 --- a/src/hash/sha1/collisiondetect.c +++ b/src/hash/sha1/collisiondetect.c @@ -24,21 +24,21 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx) { - assert(ctx); + GIT_ASSERT_ARG(ctx); SHA1DCInit(&ctx->c); return 0; } int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) { - assert(ctx); + GIT_ASSERT_ARG(ctx); SHA1DCUpdate(&ctx->c, data, len); return 0; } int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx) { - assert(ctx); + GIT_ASSERT_ARG(ctx); if (SHA1DCFinal(out->id, &ctx->c)) { git_error_set(GIT_ERROR_SHA1, "SHA1 collision attack detected"); return -1; diff --git a/src/hash/sha1/common_crypto.c b/src/hash/sha1/common_crypto.c index 0449a3c9d..4250e0b61 100644 --- a/src/hash/sha1/common_crypto.c +++ b/src/hash/sha1/common_crypto.c @@ -26,7 +26,7 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx) { - assert(ctx); + GIT_ASSERT_ARG(ctx); CC_SHA1_Init(&ctx->c); return 0; } @@ -35,7 +35,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len) { const unsigned char *data = _data; - assert(ctx); + GIT_ASSERT_ARG(ctx); while (len > 0) { CC_LONG chunk = (len > CC_LONG_MAX) ? CC_LONG_MAX : (CC_LONG)len; @@ -51,7 +51,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len) int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx) { - assert(ctx); + GIT_ASSERT_ARG(ctx); CC_SHA1_Final(out->id, &ctx->c); return 0; } diff --git a/src/hash/sha1/mbedtls.c b/src/hash/sha1/mbedtls.c index e44343fcf..04e7da5fa 100644 --- a/src/hash/sha1/mbedtls.c +++ b/src/hash/sha1/mbedtls.c @@ -19,28 +19,28 @@ int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) { - assert(ctx); - mbedtls_sha1_free(&ctx->c); + if (ctx) + mbedtls_sha1_free(&ctx->c); } int git_hash_sha1_init(git_hash_sha1_ctx *ctx) { - assert(ctx); - mbedtls_sha1_init(&ctx->c); - mbedtls_sha1_starts(&ctx->c); - return 0; + GIT_ASSERT_ARG(ctx); + mbedtls_sha1_init(&ctx->c); + mbedtls_sha1_starts(&ctx->c); + return 0; } int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) { - assert(ctx); - mbedtls_sha1_update(&ctx->c, data, len); - return 0; + GIT_ASSERT_ARG(ctx); + mbedtls_sha1_update(&ctx->c, data, len); + return 0; } int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx) { - assert(ctx); - mbedtls_sha1_finish(&ctx->c, out->id); - return 0; + GIT_ASSERT_ARG(ctx); + mbedtls_sha1_finish(&ctx->c, out->id); + return 0; } diff --git a/src/hash/sha1/openssl.c b/src/hash/sha1/openssl.c index ba3212ff2..68d9611d4 100644 --- a/src/hash/sha1/openssl.c +++ b/src/hash/sha1/openssl.c @@ -24,7 +24,7 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx) { - assert(ctx); + GIT_ASSERT_ARG(ctx); if (SHA1_Init(&ctx->c) != 1) { git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to initialize hash context"); @@ -36,7 +36,7 @@ int git_hash_sha1_init(git_hash_sha1_ctx *ctx) int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) { - assert(ctx); + GIT_ASSERT_ARG(ctx); if (SHA1_Update(&ctx->c, data, len) != 1) { git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to update hash"); @@ -48,7 +48,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx) { - assert(ctx); + GIT_ASSERT_ARG(ctx); if (SHA1_Final(out->id, &ctx->c) != 1) { git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to finalize hash"); diff --git a/src/hash/sha1/win32.c b/src/hash/sha1/win32.c index b1266cca0..a6e7061c6 100644 --- a/src/hash/sha1/win32.c +++ b/src/hash/sha1/win32.c @@ -164,7 +164,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_sha1_ctx *ctx, const void *_data, { const BYTE *data = (BYTE *)_data; - assert(ctx->ctx.cryptoapi.valid); + GIT_ASSERT(ctx->ctx.cryptoapi.valid); while (len > 0) { DWORD chunk = (len > MAXDWORD) ? MAXDWORD : (DWORD)len; @@ -186,7 +186,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_sha1_ctx *ctx) DWORD len = 20; int error = 0; - assert(ctx->ctx.cryptoapi.valid); + GIT_ASSERT(ctx->ctx.cryptoapi.valid); if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out->id, &len, 0)) { git_error_set(GIT_ERROR_OS, "legacy hash data could not be finished"); @@ -286,7 +286,7 @@ int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) { int error = 0; - assert(ctx); + GIT_ASSERT_ARG(ctx); /* * When compiled with GIT_THREADS, the global hash_prov data is @@ -303,27 +303,30 @@ int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) int git_hash_sha1_init(git_hash_sha1_ctx *ctx) { - assert(ctx && ctx->type); + GIT_ASSERT_ARG(ctx); + GIT_ASSERT_ARG(ctx->type); return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx); } int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) { - assert(ctx && ctx->type); + GIT_ASSERT_ARG(ctx); + GIT_ASSERT_ARG(ctx->type); return (ctx->type == CNG) ? hash_cng_update(ctx, data, len) : hash_cryptoapi_update(ctx, data, len); } int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx) { - assert(ctx && ctx->type); + GIT_ASSERT_ARG(ctx); + GIT_ASSERT_ARG(ctx->type); return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx); } void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) { - assert(ctx); - - if (ctx->type == CNG) + if (!ctx) + return; + else if (ctx->type == CNG) hash_ctx_cng_cleanup(ctx); else if(ctx->type == CRYPTOAPI) hash_ctx_cryptoapi_cleanup(ctx); |