]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files-backend: don't look at an aborted transaction
authorJeff King <peff@peff.net>
Thu, 21 Mar 2019 09:28:54 +0000 (05:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Mar 2019 06:52:54 +0000 (15:52 +0900)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c

index 0a2929bf6a22f6e5b35cd04c77b1151e17a7e3e8..09608e6c4376ba64b3008f6a8f91bedc04966dc2 100644 (file)
@@ -2712,12 +2712,16 @@ static int files_transaction_prepare(struct ref_store *ref_store,
                         * file. But we do need to leave it locked, so
                         * that somebody else doesn't pack a reference
                         * that we are trying to delete.
+                        *
+                        * We need to disconnect our transaction from
+                        * backend_data, since the abort (whether successful or
+                        * not) will free it.
                         */
+                       backend_data->packed_transaction = NULL;
                        if (ref_transaction_abort(packed_transaction, err)) {
                                ret = TRANSACTION_GENERIC_ERROR;
                                goto cleanup;
                        }
-                       backend_data->packed_transaction = NULL;
                }
        }