git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fixup! propagate errno from failing read

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 18, 2021, 22:19 UTC
Message-ID
<YR2HVU4KBCihqoYZ@google.com>
In-Reply-To
<20210817161419.3606302-1-jonathantanmy@google.com>
Hi,
Jonathan Tan wrote:
> Han-Wen Nienhuys wrote:
Show 17 quoted lines
>> diff --git a/refs/files-backend.c b/refs/files-backend.c
>> index 0d96eeba61b..f546cc3cc3d 100644
>> --- a/refs/files-backend.c
>> +++ b/refs/files-backend.c
>> @@ -454,6 +454,7 @@ stat_ref:
>>  	}
>>  	strbuf_reset(&sb_contents);
>>  	if (strbuf_read(&sb_contents, fd, 256) < 0) {
>> +		myerr = errno;
>>  		close(fd);
>>  		goto out;
>>  	}
>
> Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
>
> Thanks - a straightforward fixup. (I don't think we need the errno from
> close() in this case.)

This looks good as far as it goes, but how do we know this has covered all the code paths? Let's see.

The only nonobvious paths are
 stat_ref:
	/*
	 * We might have to loop back here to avoid a race
	 * condition: first we lstat() the file, then we try
	 * to read it as a link or as a file.  But if somebody
	 * changes the type of the file (file <-> directory
	 * <-> symlink) between the lstat() and reading, then
	 * we don't want to report that as an error but rather
	 * try again starting with the lstat().
	 *
	 * We'll keep a count of the retries, though, just to avoid
	 * any confusing situation sending us into an infinite loop.
	 */
	if (remaining_retries-- <= 0)
		goto out;
and
	ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr);
 out:
	if (ret && !myerr)
		BUG("returning non-zero %d, should have set myerr!", ret);

For the 'stat_ref' case, we have to check that whenever we 'goto stat_ref', we set myerr moments before. Fortunately, that is the case.

For the 'fall through into out' case, we have the check the parse_loose_ref_contents always sets *failure_errno on error. That is also the case.

So this indeed covers all our cases, and the BUG now correctly reflects an invariant we can count on. Thanks for the fix, and thanks for looking it over.

Sincerely, Jonathan

Previous: Jonathan TanNext: Junio C Hamano
Message 3 of 14 in “fixup! propagate errno from failing read”
  1. fixup! propagate errno from failing readHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  2. Jonathan TanAug 17, 2021
  3. Jonathan NiederAug 18, 2021
  4. Junio C HamanoAug 17, 2021
  5. Han-Wen NienhuysAug 18, 2021
  6. Junio C HamanoAug 18, 2021
  7. Junio C HamanoAug 19, 2021
  8. Han-Wen NienhuysAug 19, 2021
  9. Jeff KingAug 19, 2021
  10. t3200: refactor symlink testCarlo Marcelo Arenas Belón, Aug 19, 2021
  11. Eric SunshineAug 19, 2021
  12. t3200: refactor symlink test from hn/refs-errno-cleanupCarlo Marcelo Arenas Belón, Aug 19, 2021
  13. Junio C HamanoAug 19, 2021
  14. Junio C HamanoAug 19, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.