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>
This commit is contained in:

committed by
Junio C Hamano

parent
9da95bda74
commit
c98d762ed9
@ -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) {
|
||||
|
Reference in New Issue
Block a user