Skip to content

Commit 75e1737

Browse files
committed
hash: openssl: check return values of SHA1_* functions
The OpenSSL functions `SHA1_Init`, `SHA1_Update` and `SHA1_Final` all return 1 for success and 0 otherwise, but we never check their return values. Do so.
1 parent 1bf173c commit 75e1737

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/hash/hash_openssl.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,36 @@ struct git_hash_ctx {
2323
GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
2424
{
2525
assert(ctx);
26-
SHA1_Init(&ctx->c);
26+
27+
if (SHA1_Init(&ctx->c) != 1) {
28+
giterr_set(GITERR_SHA1, "hash_openssl: failed to initialize hash context");
29+
return -1;
30+
}
31+
2732
return 0;
2833
}
2934

3035
GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
3136
{
3237
assert(ctx);
33-
SHA1_Update(&ctx->c, data, len);
38+
39+
if (SHA1_Update(&ctx->c, data, len) != 1) {
40+
giterr_set(GITERR_SHA1, "hash_openssl: failed to update hash");
41+
return -1;
42+
}
43+
3444
return 0;
3545
}
3646

3747
GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
3848
{
3949
assert(ctx);
40-
SHA1_Final(out->id, &ctx->c);
50+
51+
if (SHA1_Final(out->id, &ctx->c) != 1) {
52+
giterr_set(GITERR_SHA1, "hash_openssl: failed to finalize hash");
53+
return -1;
54+
}
55+
4156
return 0;
4257
}
4358

0 commit comments

Comments
 (0)