Re: Increase some limits in git-mailinfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

>  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?

> +			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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]