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

Re: Increase some limits in git-mailinfo

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 26, 2007, 19:34 UTC
Message-ID
<Pine.LNX.4.63.0702262020590.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<Pine.LNX.4.64.0702261107060.12485@woody.linux-foundation.org>
Hi,
On Mon, 26 Feb 2007, Linus Torvalds wrote:
> +
> +	/* Count mbox From headers as headers */
> +	if (!memcmp(line, "From ", 5) || !memcmp(line, ">From ", 6))
I know that you copied that, but why not use the new prefixcmp() function?
Show 31 quoted lines
>  static int read_one_header_line(char *line, int sz, FILE *in)
>  {
> -	int ofs = 0;
> -	while (ofs < sz) {
> -		int peek, len;
> -		if (fgets(line + ofs, sz - ofs, in) == NULL)
> -			break;
> -		len = eatspace(line + ofs);
> -		if ((len == 0) || !is_rfc2822_header(line)) {
> -			/* Re-add the newline */
> -			line[ofs + len] = '\n';
> -			line[ofs + len + 1] = '\0';
> -			break;
> -		}
> -		ofs += len;
> -		/* Yuck, 2822 header "folding" */
> +	int len;
> +
> +	/* Get the first part of the line.. */
> +	if (!fgets(line, sz, in))
> +		return 0;
> +
> +	/*
> +	 * Is it an empty line or not a valid rfc2822 header?
> +	 * If so, stop here, and return false ("not a header")
> +	 */
> +	len = eatspace(line);
> +	if (!len || !is_rfc2822_header(line)) {
> +		/* Re-add the newline */
> +		line[len] = '\n';
> +		line[len + 1] = '\0';

Just a micro-issue: if the input ends in the middle of a header line, _and_ this line is of exactly the right size (sz), then len + 1 is not necessarily smaller than sz, right?

It's not like this can be used for a DOS or stuff, but I try to get more aware of off-by-one bugs, which I introduced all too often...

> +		addlen = eatspace(continuation);
> +		if (len < sz) {

Shouldn't this be "sz - 1"? We are setting "line[len] = 0;" later... While at it, we can always check for "addlen > 0", just in case?

But then, should it not be rather "sz - 2", because we want to _add_ something to the line?

Show 13 quoted lines
> +			if (addlen >= sz - len)
> +				addlen = sz - len - 1;
> +			memcpy(line + len, continuation, addlen);
> +			len += addlen;
> +		}
>  	}
> -	/* Count mbox From headers as headers */
> -	if (!ofs && (!memcmp(line, "From ", 5) || !memcmp(line, ">From ", 6)))
> -		ofs = 1;
> -	return ofs;
> +	line[len] = 0;
> +
> +	return 1;

Ciao, Dscho

Previous: Linus TorvaldsNext: Linus Torvalds
Message 3 of 8 in “Increase some limits in git-mailinfo”
  1. Linus TorvaldsFeb 26, 2007
  2. Linus TorvaldsFeb 26, 2007
  3. Johannes SchindelinFeb 26, 2007
  4. Linus TorvaldsFeb 26, 2007
  5. Johannes SchindelinFeb 26, 2007
  6. Linus TorvaldsFeb 26, 2007
  7. Johannes SchindelinFeb 26, 2007
  8. Linus TorvaldsFeb 26, 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.