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

Re: [PATCH 8/6 v2] receive-pack: Send internal errors over side-band #2

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 11, 2010, 15:05 UTC
Message-ID
<20100211150547.GL2747@spearce.org>
In-Reply-To
<4B73C0FF.5020503@viscovery.net>
Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 14 quoted lines
> Shawn O. Pearce schrieb:
>> +static void report_message(const char *prefix, const char *err, va_list params)
>> +{
>> +	int sz = strlen(prefix);
>> +	char msg[4096];
>> +
>> +	strncpy(msg, prefix, sz);
>> +	sz += vsnprintf(msg + sz, sizeof(msg) - sz, err, params);
>> +	if (sz > (sizeof(msg) - 1))
>> +		sz = sizeof(msg) - 1;
>> +	msg[sz++] = '\n';
>
> Sorry, still no joy - the terminating NUL is missing (I should have  
> noticed this in your v1 already).
Why is it necessary?

Once the msg buffer is prepared, its written using its length, sz, not its NUL termination status. Neither send_sideband() nor xwrite() care about NUL termination.

The only reason to put a NUL onto this buffer is so you can do "p msg" within GDB and get a useful result. We don't typically do this in these contexts.

Or did my MTA inject additional C code I didn't write?
Show 7 quoted lines
> I suggest to forgo the length check for 
> simplicity because this function is only called with data that is already 
> guaranteed to be less than 1000 bytes, i.e.:
>
> 	strncpy(msg, prefix, sz);
> 	/* data is guaranteed to fit due to packet length limit in  
> read_head_info() */

Yea, that's true now. We probably could have used 1200 bytes for the msg buffer, rather than 4096. Even the huge warnings about current branch behavior are broken up into one string per line.

-- 
Shawn.
Previous: Johannes SixtNext: Johannes Sixt
Message 8 of 10 in “t5401: Use a bare repository for the remote peer”
  1. 7/6 t5401: Use a bare repository for the remote peerShawn O. Pearce, Feb 10, 2010
  2. 8/6 receive-pack: Send internal errors over side-band #2Shawn O. Pearce, Feb 10, 2010
  3. Johannes SixtFeb 10, 2010
  4. Junio C HamanoFeb 10, 2010
  5. Johannes SixtFeb 10, 2010
  6. 8/6 receive-pack: Send internal errors over side-band #2Shawn O. Pearce, Feb 10, 2010
  7. Johannes SixtFeb 11, 2010
  8. Shawn O. PearceFeb 11, 2010
  9. Johannes SixtFeb 11, 2010
  10. Shawn O. PearceFeb 10, 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.