[PATCH v4 1/8] convert: Safer handling of $Id$ contraction.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
Date: Tuesday, April 6, 2010 - 5:46 am

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             |   12 ++++++++++++
 t/t0021-conversion.sh |   16 ++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/convert.c b/convert.c
index 4f8fcb7..239fa0a 100644
--- a/convert.c
+++ b/convert.c
@@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size)
 				cnt++;
 				break;
 			}
+			if (ch == '\n')
+				break;
 		}
 	}
 	return cnt;
@@ -455,6 +457,11 @@ static int ident_to_git(const char *path, const char *src, size_t len,
 			dollar = memchr(src + 3, '$', len - 3);
 			if (!dollar)
 				break;
+			if (memchr(src + 3, '\n', dollar - src - 3)) {
+				/* Line break before the next dollar. */
+				continue;
+			}
+
 			memcpy(dst, "Id$", 3);
 			dst += 3;
 			len -= dollar + 1 - src;
@@ -514,6 +521,11 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
 				break;
 			}
 
+			if (memchr(src + 3, '\n', dollar - src - 3)) {
+				/* Line break before the next dollar. */
+				continue;
+			}
+
 			len -= dollar + 1 - src;
 			src  = dollar + 1;
 		} else {
diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index 6cb8d60..29438c5 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -65,17 +65,21 @@ test_expect_success expanded_in_repo '
 		echo "\$Id:NoSpaceAtFront \$"
 		echo "\$Id:NoSpaceAtEitherEnd\$"
 		echo "\$Id: NoTerminatingSymbol"
+		echo "\$Id: Foreign Commit With Spaces \$"
+		echo "\$Id: NoTerminatingSymbolAtEOF"
 	} > expanded-keywords &&
 
 	{
 		echo "File with expanded keywords"
-		echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-		echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-		echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-		echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-		echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-		echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
 		echo "\$Id: NoTerminatingSymbol"
+		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: NoTerminatingSymbolAtEOF"
 	} > expected-output &&
 
 	git add expanded-keywords &&
-- 
1.7.0.3.316.g33b5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH v4 0/8] Attribute and conversion patches, =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 1/8] convert: Safer handling of $Id$ contraction., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 2/8] convert: Keep foreign $Id$ on checkout., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 3/8] status: Added missing calls to diff_unmodif ..., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 4/8] diff: Filter files that have changed only d ..., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 5/8] convert: Added core.refilteronadd feature., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 6/8] attr: Fixed debug output for macro expansion., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 7/8] attr: Allow multiple changes to an attribut ..., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
[PATCH v4 8/8] attr: Expand macros immediately when encoun ..., =?UTF-8?q?Henrik=20G ..., (Tue Apr 6, 5:46 am)
Re: [PATCH v4 3/8] status: Added missing calls to diff_unm ..., Henrik Grubbström, (Mon Apr 12, 6:00 am)
Re: [PATCH v4 4/8] diff: Filter files that have changed on ..., Henrik Grubbström, (Fri Apr 16, 8:30 am)