Skip to content

Commit d3322eb

Browse files
peffgitster
authored andcommitted
refs/files-backend: don't look at an aborted transaction
When deleting refs, we hold packed-refs.lock and prepare a packed transaction to drop the refs from the packed-refs file. If it turns out that we don't need to rewrite the packed refs (e.g., because none of the deletions were present in the file), then we abort the transaction. If that abort succeeds, then the transaction struct will have been freed, and we set our local pointer to NULL so we don't look at it again. However, if it fails, then the struct will _still_ have been freed (because ref_transaction_abort() always frees). But we don't clean up the pointer, and will jump to our cleanup code, which will try to abort it again, causing a use-after-free. It's actually impossible for this to trigger in practice, since packed_transaction_abort() will never return anything but success. But let's fix it anyway, since that's more than we should assume about the packed-refs code (after all, we are already bothering to check for an error result which cannot be triggered). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 249e8dc commit d3322eb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

refs/files-backend.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2712,12 +2712,16 @@ static int files_transaction_prepare(struct ref_store *ref_store,
27122712
* file. But we do need to leave it locked, so
27132713
* that somebody else doesn't pack a reference
27142714
* that we are trying to delete.
2715+
*
2716+
* We need to disconnect our transaction from
2717+
* backend_data, since the abort (whether successful or
2718+
* not) will free it.
27152719
*/
2720+
backend_data->packed_transaction = NULL;
27162721
if (ref_transaction_abort(packed_transaction, err)) {
27172722
ret = TRANSACTION_GENERIC_ERROR;
27182723
goto cleanup;
27192724
}
2720-
backend_data->packed_transaction = NULL;
27212725
}
27222726
}
27232727

0 commit comments

Comments
 (0)