diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-06-14 08:49:59 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-06-14 19:26:32 +0200 |
commit | c98d762ed96ba9beead28608b3c7d1e477a8fe3d (patch) | |
tree | 1f8ca665c28c7e3719f8e4ddc5a2ff5e4c18eb74 /parallel-checkout.c | |
parent | hash: require hash algorithm in `oidread()` and `oidclr()` (diff) | |
download | git-c98d762ed96ba9beead28608b3c7d1e477a8fe3d.tar.xz git-c98d762ed96ba9beead28608b3c7d1e477a8fe3d.zip |
global: ensure that object IDs are always padded
The `oidcmp()` and `oideq()` functions only compare the prefix length as
specified by the given hash algorithm. This mandates that the object IDs
have a valid hash algorithm set, or otherwise we wouldn't be able to
figure out that prefix. As we do not have a hash algorithm in many
cases, for example when handling null object IDs, this assumption cannot
always be fulfilled. We thus have a fallback in place that instead uses
`the_repository` to derive the hash function. This implicit dependency
is hidden away from callers and can be quite surprising, especially in
contexts where there may be no repository.
In theory, we can adapt those functions to always memcmp(3P) the whole
length of their hash arrays. But there exist a couple of sites where we
populate `struct object_id`s such that only the prefix of its hash that
is actually used by the hash algorithm is populated. The remaining bytes
are left uninitialized. The fact that those bytes are uninitialized also
leads to warnings under Valgrind in some places where we copy those
bytes.
Refactor callsites where we populate object IDs to always initialize all
bytes. This also allows us to get rid of `oidcpy_with_padding()`, for
one because the input is now fully initialized, and because `oidcpy()`
will now always copy the whole hash array.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parallel-checkout.c')
-rw-r--r-- | parallel-checkout.c | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/parallel-checkout.c b/parallel-checkout.c index b5a714c711..08b960aac8 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -429,13 +429,7 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item) fixed_portion->ident = pc_item->ca.ident; fixed_portion->name_len = name_len; fixed_portion->working_tree_encoding_len = working_tree_encoding_len; - /* - * We pad the unused bytes in the hash array because, otherwise, - * Valgrind would complain about passing uninitialized bytes to a - * write() syscall. The warning doesn't represent any real risk here, - * but it could hinder the detection of actual errors. - */ - oidcpy_with_padding(&fixed_portion->oid, &pc_item->ce->oid); + oidcpy(&fixed_portion->oid, &pc_item->ce->oid); variant = data + sizeof(*fixed_portion); if (working_tree_encoding_len) { |