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

Re: [PATCH 1/2] config: check if config path is a file before parsing it

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2017, 21:05 UTC
Message-ID
<xmqq4lza840k.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170303095351.rgifjpfuvafx33jy@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
>        a. actually check ferror() after getting EOF and report the read
>           error. That catches EISDIR, along with any other unexpected
> 	  errors.

That is the most sensible, I would think (assuming that we really get EISDIR instead of silent EOF).

>        b. use an fopen wrapper that checks fstat(fileno(fh)) after the
>           open, and turns fopen(some_dir) into an error.
That's already an option with FREAD_READS_DIRECTORIES, I think.
Show 5 quoted lines
>   2. It doesn't address the root problem for git_config_from_file(),
>      which is that it is quiet when fopen fails, even if the reason is
>      something interesting besides ENOENT. The caller can't check errno
>      because it doesn't know if fopen() failed, or if the config
>      callback returned an error.
Perhaps like this one as a starting point, with FREAD_READS_DIRECTORIES?
 config.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/config.c b/config.c
index 0dac0f4cb2..af8c01c8a3 100644
--- a/config.c
+++ b/config.c
@@ -1305,6 +1305,9 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 	FILE *f;
 
 	f = fopen(filename, "r");
+	if (!f && errno != ENOENT)
+		die_errno("fopen('%s') failed", filename);
+
 	if (f) {
 		flockfile(f);
 		ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
Previous: Jeff KingNext: Ramsay Jones
Message 10 of 11 in “Improve error messages when opening a directory as file”
  1. 0/2 Improve error messages when opening a directory as fileNguyễn Thái Ngọc Duy, Mar 3, 2017
  2. 2/2 attr.c: check if .gitattributes is a file before parsing itNguyễn Thái Ngọc Duy, Mar 3, 2017
  3. 1/2 config: check if config path is a file before parsing itNguyễn Thái Ngọc Duy, Mar 3, 2017
  4. Jeff KingMar 3, 2017
  5. Duy NguyenMar 3, 2017
  6. Jeff KingMar 3, 2017
  7. Jeff KingMar 3, 2017
  8. Duy NguyenMar 3, 2017
  9. Jeff KingMar 3, 2017
  10. Junio C HamanoMar 3, 2017
  11. Ramsay JonesMar 3, 2017

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.