Skip to content

Commit

Permalink
tree: move assignments of ->tree_errno up a bit
Browse files Browse the repository at this point in the history
Both tree_ascend() and tree_pop() may cause errno to be
set/clobbered. As for the latter, we're certainly not interested in
the random values that free() etc. may leave in errno.

If tree_ascend() fails, its return value takes precedence in
determining t->visit_type and the return value, but tree_ascend() also
updates t->tree_errno appropriately, which makes sense.

But when tree_ascend() succeeds, t->tree_errno should reflect the
reason for opendir() failing, which requires that we record errno
immediately.

Bug bounty:	$20
  • Loading branch information
Villemoes authored and gperciva committed Jan 16, 2024
1 parent 697ebd6 commit c962254
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tar/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,16 @@ tree_next(struct tree *t)
t->dirname_length = t->path_length;
if (chdir(t->stack->name) != 0) {
/* chdir() failed; return error */
tree_pop(t);
t->tree_errno = errno;
tree_pop(t);
return (t->visit_type = TREE_ERROR_DIR);
}
t->depth++;
t->d = opendir(".");
if (t->d == NULL) {
t->tree_errno = errno;
r = tree_ascend(t); /* Undo "chdir" */
tree_pop(t);
t->tree_errno = errno;
t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
return (t->visit_type);
}
Expand Down

0 comments on commit c962254

Please sign in to comment.