ref_transaction_create(): disallow recursive pruning

It is nonsensical (and a little bit dangerous) to use REF_ISPRUNING without REF_NODEREF. Forbid it explicitly. Change the one REF_ISPRUNING caller to pass REF_NODEREF too. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>

Michael Haggerty committed Apr 24, 2016 at 09:48 UTC c52ce248d63a185eb0a616b361d1fd72c5c66451
3 files changed +5 -2
refs.c
+3
@@ -790,6 +790,9 @@ int ref_transaction_update(struct ref_transaction *transaction,
790 if (transaction->state != REF_TRANSACTION_OPEN)
791 die("BUG: update called for transaction that is not open");
792
793 + if ((flags & REF_ISPRUNING) && !(flags & REF_NODEREF))
794 + die("BUG: REF_ISPRUNING set without REF_NODEREF");
795 +
796 if (new_sha1 && !is_null_sha1(new_sha1) &&
797 check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
798 strbuf_addf(err, "refusing to update ref with bad name '%s'",
refs/files-backend.c
+1 -1
@@ -2087,7 +2087,7 @@ static void prune_ref(struct ref_to_prune *r)
2087 transaction = ref_transaction_begin(&err);
2088 if (!transaction ||
2089 ref_transaction_delete(transaction, r->name, r->sha1,
2090 - REF_ISPRUNING, NULL, &err) ||
2090 + REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
2091 ref_transaction_commit(transaction, &err)) {
2092 ref_transaction_free(transaction);
2093 error("%s", err.buf);
refs/refs-internal.h
+1 -1
@@ -15,7 +15,7 @@
15
16 /*
17 * Used as a flag in ref_update::flags when a loose ref is being
18 - * pruned.
18 + * pruned. This flag must only be used when REF_NODEREF is set.
19 */
20 #define REF_ISPRUNING 0x04
21