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

Re: [PATCH] Limit filename for format-patch

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Feb 24, 2007, 11:24 UTC
Message-ID
<200702241224.41208.robin.rosenberg@dewire.com>
In-Reply-To
<7vtzxcym3t.fsf@assigned-by-dhcp.cox.net>
lördag 24 februari 2007 09:51 skrev Junio C Hamano:
Show 21 quoted lines
> Robin Rosenberg <robin.rosenberg@dewire.com> writes:
> 
> > -static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
> > +static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
> >  {
> > -	char filename[1024];
> > +	char filename[PATH_MAX];
> >  	char *sol;
> >  	int len = 0;
> > -	int suffix_len = strlen(fmt_patch_suffix) + 10; /* ., NUL and slop */
> > +	int suffix_len = strlen(fmt_patch_suffix) + 1;
> >  
> >  	if (output_directory) {
> > -		strlcpy(filename, output_directory, 1000);
> > +		if (strlen(output_directory) >= sizeof(filename) - 64 - suffix_len)
> > +			return error("name of output directory is too long");
> > +		strlcpy(filename, output_directory, sizeof(filename) - suffix_len);
> 
> Sorry for a late doubt, but I started wondering if we should use
> NAME_MAX instead of hardcoded 64.  Purists might argue for using
> pathconf() but I think it is an overkill.

I think it'd sane to keep the name much shorter than what is actually possible. The patches will have a counter to keep the names unique anyway.

Show 11 quoted lines
> 
> NAME_MAX is 255 on Linux, POSIX says it should be 14 at least
> (and further says if the platform supports only smaller max,
> NAME_MAX should not be defined -- heh).  I do not know how
> universal NAME_MAX is defined, and I hate dealing with header
> incompatibility across different systems, so I am tempted to
> just do something like:
> 
> #define FORMAT_PATCH_NAME_MAX 64
> 
> locally, and use that instead.
Ok with me.
-- robin
Previous: Junio C Hamano
Message 9 of 9 in “Limit filename for format-patch”
  1. Limit filename for format-patchRobin Rosenberg, Feb 23, 2007
  2. Johannes SchindelinFeb 23, 2007
  3. Robin RosenbergFeb 23, 2007
  4. Limit filename for format-patchRobin Rosenberg, Feb 23, 2007
  5. Limit filename for format-patchRobin Rosenberg, Feb 23, 2007
  6. Johannes SchindelinFeb 24, 2007
  7. Junio C HamanoFeb 24, 2007
  8. Junio C HamanoFeb 24, 2007
  9. Robin RosenbergFeb 24, 2007

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.