Skip to content

Commit 630942a

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 667b545 commit 630942a

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

reftable/stack.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
590590
err = stack_uptodate(st);
591591
if (err < 0)
592592
goto done;
593-
594-
if (err > 1) {
593+
if (err > 0) {
595594
err = REFTABLE_LOCK_ERROR;
596595
goto done;
597596
}
@@ -713,10 +712,6 @@ static int stack_try_add(struct reftable_stack *st,
713712
int err = reftable_stack_init_addition(&add, st);
714713
if (err < 0)
715714
goto done;
716-
if (err > 0) {
717-
err = REFTABLE_LOCK_ERROR;
718-
goto done;
719-
}
720715

721716
err = reftable_addition_add(&add, write_table, arg);
722717
if (err < 0)

0 commit comments

Comments
 (0)