Skip to content

Commit

Permalink
Avoid clobbered errno in process_lines()
Browse files Browse the repository at this point in the history
The errno which was used in bsdtar_errc() might have been set by the
process() callback.

Reported by:	Rasmus Villemoes
Bug bounty:	$10
  • Loading branch information
gperciva committed Sep 28, 2023
1 parent 9bea927 commit e09edb2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tar/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
size_t seplen;
int lastcharwasr = 0;
int ret;
int fread_errno;

if (null) {
separator = "";
Expand Down Expand Up @@ -335,6 +336,7 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
/* Get some more data into the buffer. */
bytes_wanted = buff + buff_length - buff_end;
bytes_read = fread(buff_end, 1, bytes_wanted, f);
fread_errno = errno;
buff_end += bytes_read;
/* Process all complete lines in the buffer. */
while (line_end < buff_end) {
Expand Down Expand Up @@ -363,7 +365,7 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
if (feof(f))
break;
if (ferror(f))
bsdtar_errc(bsdtar, 1, errno,
bsdtar_errc(bsdtar, 1, fread_errno,
"Can't read %s", pathname);
if (line_start > buff) {
/* Move a leftover fractional line to the beginning. */
Expand Down

0 comments on commit e09edb2

Please sign in to comment.