Skip to content

Commit e0b8c84

Browse files
Eric Wonggitster
authored andcommitted
treewide: fix various bugs w/ OpenSSL 3+ EVP API
The OpenSSL 3+ EVP API for SHA-* cannot support our prior use cases supported by other SHA-* implementations. It has the following differences: 1. ->init_fn is required before all use 2. struct assignments don't work and requires ->clone_fn 3. can't support ->update_fn after ->final_*fn While fixing cases 1 and 2 is merely the matter of calling ->init_fn and ->clone_fn as appropriate, fixing case 3 requires calling ->final_*fn on a temporary context that's cloned from the primary context. Reported-by: Bagas Sanjaya <[email protected]> Link: https://lore.kernel.org/[email protected]/ Helped-by: brian m. carlson <[email protected]> Fixes: 3e440ea ("sha256: avoid functions deprecated in OpenSSL 3+") Fixes: bda9c12 ("avoid SHA-1 functions deprecated in OpenSSL 3+") Signed-off-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bda9c12 commit e0b8c84

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

builtin/fast-import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11031103
|| (pack_size + PACK_SIZE_THRESHOLD + len) < pack_size)
11041104
cycle_packfile();
11051105

1106+
the_hash_algo->init_fn(&checkpoint.ctx);
11061107
hashfile_checkpoint(pack_file, &checkpoint);
11071108
offset = checkpoint.offset;
11081109

builtin/index-pack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ static void parse_pack_objects(unsigned char *hash)
11661166
struct ofs_delta_entry *ofs_delta = ofs_deltas;
11671167
struct object_id ref_delta_oid;
11681168
struct stat st;
1169+
git_hash_ctx tmp_ctx;
11691170

11701171
if (verbose)
11711172
progress = start_progress(
@@ -1202,7 +1203,9 @@ static void parse_pack_objects(unsigned char *hash)
12021203

12031204
/* Check pack integrity */
12041205
flush();
1205-
the_hash_algo->final_fn(hash, &input_ctx);
1206+
the_hash_algo->init_fn(&tmp_ctx);
1207+
the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
1208+
the_hash_algo->final_fn(hash, &tmp_ctx);
12061209
if (!hasheq(fill(the_hash_algo->rawsz), hash))
12071210
die(_("pack is corrupted (SHA1 mismatch)"));
12081211
use(the_hash_algo->rawsz);

builtin/unpack-objects.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
608608
{
609609
int i;
610610
struct object_id oid;
611+
git_hash_ctx tmp_ctx;
611612

612613
read_replace_refs = 0;
613614

@@ -668,7 +669,9 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
668669
the_hash_algo->init_fn(&ctx);
669670
unpack_all();
670671
the_hash_algo->update_fn(&ctx, buffer, offset);
671-
the_hash_algo->final_oid_fn(&oid, &ctx);
672+
the_hash_algo->init_fn(&tmp_ctx);
673+
the_hash_algo->clone_fn(&tmp_ctx, &ctx);
674+
the_hash_algo->final_oid_fn(&oid, &tmp_ctx);
672675
if (strict) {
673676
write_rest();
674677
if (fsck_finish(&fsck_options))

bulk-checkin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ static int deflate_to_pack(struct bulk_checkin_packfile *state,
270270
type, size);
271271
the_hash_algo->init_fn(&ctx);
272272
the_hash_algo->update_fn(&ctx, obuf, header_len);
273+
the_hash_algo->init_fn(&checkpoint.ctx);
273274

274275
/* Note: idx is non-NULL when we are writing */
275276
if ((flags & HASH_WRITE_OBJECT) != 0)

csum-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
208208
lseek(f->fd, offset, SEEK_SET) != offset)
209209
return -1;
210210
f->total = offset;
211-
f->ctx = checkpoint->ctx;
211+
the_hash_algo->clone_fn(&f->ctx, &checkpoint->ctx);
212212
f->offset = 0; /* hashflush() was called in checkpoint */
213213
return 0;
214214
}

0 commit comments

Comments
 (0)