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

Re: [PATCH] Improved error messages when temporary file creation fails

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 7, 2010, 23:56 UTC
Message-ID
<idmhjl$n1j$1@dough.gmane.org>
In-Reply-To
<20101207212041.GG25767@bzzt.net>
Arnout Engelen wrote:
> On Tue, Dec 07, 2010 at 12:56:17PM -0800, Junio C Hamano wrote:
Show 28 quoted lines
>>> +   char origtemplate[255];
>>> +   strlcpy(origtemplate, template, 255);
>> 
>> Why "255"?
> 
> Random - 'i had to choose something'.
> 
>> It may happen to be sufficiently large for the current callers, but what
>> provisions if any are made to help the compiler or the runtime protect us
>> from new and broken callers?  Use of strlcpy() there hides the issue from
>> the runtime by avoiding segfault, but it actively harms us by making the
>> code silently behave incorrectly without segfaulting, no?
> 
> Only in a small way: when a bigger template is encountered and the mkstemp 
> call succeeds, there is no problem. Only when xmkstemp fails *and* clears the
> template, the diagnostic error message shows a truncated version of the 
> original.
> 
> I *could* dynamically allocate space for the original template string, but that
> would mean I'd need to do a malloc() instead of putting the buffer on the stack
> like this, and free() it afterwards. I'm not too concerned about the 
> performance hit here (presumably the I/O that comes with creating and using 
> the temporary file here is orders of magnitude slower than that malloc() 
> anyway), but it would also make the code a bit less easy to read.
> 
> What do you think would be preferable here, a simple fixed-length buffer on the
> stack that might cause a truncated error message or a dynamically-allocated 
> one that makes the code somewhat more complicated?
Why not use PATH_MAX instead of 255?
P.S. I'm sory for cutting up CC list...
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Previous: Arnout EngelenNext: Jonathan Nieder
Message 5 of 12 in “Improved error messages when temporary file creation fails”
  1. Improved error messages when temporary file creation failsArnout Engelen, Dec 7, 2010
  2. Jonathan NiederDec 7, 2010
  3. Junio C HamanoDec 7, 2010
  4. Arnout EngelenDec 7, 2010
  5. Jakub NarebskiDec 7, 2010
  6. Jonathan NiederDec 8, 2010
  7. Junio C HamanoDec 8, 2010
  8. Arnout EngelenDec 18, 2010
  9. Jonathan NiederDec 18, 2010
  10. Junio C HamanoDec 18, 2010
  11. Junio C HamanoDec 18, 2010
  12. Arnout EngelenDec 18, 2010

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.