diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-03-25 11:02:38 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-25 09:51:11 -0700 |
commit | 630942a873ae0f1d067efaaf7b4d1b05cfb3a141 (patch) | |
tree | 511a0c02a9fd49379578fe618b3e8d07e2bfbec6 /reftable | |
parent | 667b545c625a860b42f335db3c5a04020e6131f6 (diff) | |
download | git-630942a873ae0f1d067efaaf7b4d1b05cfb3a141.tar.gz |
reftable/stack: fix error handling in `reftable_stack_init_addition()`
In `reftable_stack_init_addition()` we call `stack_uptodate()` after
having created the lockfile to check whether the stack was modified
concurrently, which is indicated by a positive return code from the
latter function. If so, we return a `REFTABLE_LOCK_ERROR` to the caller
and abort the addition.
The error handling has an off-by-one though because we check whether the
error code is `> 1` instead of `> 0`. Thus, instead of returning the
locking error, we would return a positive value. One of the callers of
`reftable_stack_init_addition()` works around this bug by repeating the
error code check without the off-by-one. But other callers are subtly
broken by this bug.
Fix this by checking for `err > 0` instead. This has the consequence
that `reftable_stack_init_addition()` won't ever return a positive error
code anymore, but will instead return `REFTABLE_LOCK_ERROR` now. Thus,
we can drop the check for a positive error code in `stack_try_add()`
now.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable')
-rw-r--r-- | reftable/stack.c | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/reftable/stack.c b/reftable/stack.c index 1ecf1b9751..92d9a7facb 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -590,8 +590,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add, err = stack_uptodate(st); if (err < 0) goto done; - - if (err > 1) { + if (err > 0) { err = REFTABLE_LOCK_ERROR; goto done; } @@ -713,10 +712,6 @@ static int stack_try_add(struct reftable_stack *st, int err = reftable_stack_init_addition(&add, st); if (err < 0) goto done; - if (err > 0) { - err = REFTABLE_LOCK_ERROR; - goto done; - } err = reftable_addition_add(&add, write_table, arg); if (err < 0) |