git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: "\"Henrik Grubbström (Grubba)\"" <grubba@grubba.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/4] convert: Safer handling of $Id$ contraction.
Date: Mon, 15 Mar 2010 19:16:06 +0100	[thread overview]
Message-ID: <4B9E7966.4060300@lsrfire.ath.cx> (raw)
In-Reply-To: <be7e603837d8f55461c4d654fb07bd61c97b70e6.1268664693.git.grubba@grubba.org>

Am 15.03.2010 16:30, schrieb Henrik Grubbström (Grubba):
> The code to contract $Id:xxxxx$ strings could eat an arbitrary amount
> of source text if the terminating $ was lost. It now refuses to
> contract $Id:xxxxx$ strings spanning multiple lines.
> 
> Signed-off-by: Henrik Grubbström <grubba@grubba.org>
> ---
> The behaviour implemented by the patch is in line with what other
> VCSes that implement $Id$ do.
> 
>  convert.c             |   17 +++++++++++++++--
>  t/t0021-conversion.sh |   16 ++++++++++------
>  2 files changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/convert.c b/convert.c
> index 4f8fcb7..91207ab 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -425,6 +425,7 @@ static int count_ident(const char *cp, unsigned long size)
>  				cnt++;
>  				break;
>  			}
> +			if (ch == '\n') break;

Style:

			if (ch == '\n')
				break;

>  		}
>  	}
>  	return cnt;
> @@ -433,7 +434,7 @@ static int count_ident(const char *cp, unsigned long size)
>  static int ident_to_git(const char *path, const char *src, size_t len,
>                          struct strbuf *buf, int ident)
>  {
> -	char *dst, *dollar;
> +	char *dst, *dollar, *nl;
>  
>  	if (!ident || !count_ident(src, len))
>  		return 0;
> @@ -455,6 +456,12 @@ static int ident_to_git(const char *path, const char *src, size_t len,
>  			dollar = memchr(src + 3, '$', len - 3);
>  			if (!dollar)
>  				break;
> +			nl = memchr(src + 3, '\n', len - 3);
> +			if (nl && nl < dollar) {
> +				/* Line break before the next dollar. */
> +				continue;
> +			}
> +

You only need to search up to the previously found dollar sign here:

			if (memchr(src + 3, '\n', dollar - src - 3))
				continue;

>  			memcpy(dst, "Id$", 3);
>  			dst += 3;
>  			len -= dollar + 1 - src;
> @@ -470,7 +477,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
>                               struct strbuf *buf, int ident)
>  {
>  	unsigned char sha1[20];
> -	char *to_free = NULL, *dollar;
> +	char *to_free = NULL, *dollar, *nl;
>  	int cnt;
>  
>  	if (!ident)
> @@ -514,6 +521,12 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
>  				break;
>  			}
>  
> +			nl = memchr(src + 3, '\n', len - 3);
> +			if (nl && nl < dollar) {
> +				/* Line break before the next dollar. */
> +				continue;
> +			}
> +

Ditto.

René

  parent reply	other threads:[~2010-03-15 18:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-15 15:30 [PATCH 0/4] ident attribute related patches (resend w/ testsuite) Henrik Grubbström (Grubba)
2010-03-15 15:30 ` [PATCH 1/4] convert: Safer handling of $Id$ contraction Henrik Grubbström (Grubba)
2010-03-15 15:30   ` [PATCH 2/4] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba)
2010-03-15 15:30     ` [PATCH 3/4] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba)
2010-03-15 15:30       ` [PATCH 4/4] convert: Added core.refilteronadd feature Henrik Grubbström (Grubba)
2010-03-15 15:42       ` [PATCH 3/4] convert: Inhibit contraction of foreign $Id$ during stats Bert Wesarg
2010-03-15 18:32         ` Henrik Grubbström
2010-03-15 15:39   ` [PATCH 1/4] convert: Safer handling of $Id$ contraction Bert Wesarg
2010-03-15 18:21     ` Henrik Grubbström
2010-03-15 18:16   ` René Scharfe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-03-01 16:16 Henrik Grubbström
2010-03-03  1:10 ` Junio C Hamano
2010-03-03 10:40   ` Henrik Grubbström
2010-03-09  9:22     ` Henrik Grubbström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B9E7966.4060300@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=grubba@grubba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).