convert: Safer handling of $Id$ contraction.
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Henrik Grubbström committed
Apr 6, 2010 at 14:46 UTC
a9f3049f6c152d4e6c26b15f7eeb08660aaadca3
2 files changed
+22
-6
convert.c
+12
@@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size)
425
cnt++;
426
break;
427
}
428
+ if (ch == '\n')
429
+ break;
430
}
431
}
432
return cnt;
@@ -455,6 +457,11 @@ static int ident_to_git(const char *path, const char *src, size_t len,
457
dollar = memchr(src + 3, '$', len - 3);
458
if (!dollar)
459
break;
460
+ if (memchr(src + 3, '\n', dollar - src - 3)) {
461
+ /* Line break before the next dollar. */
462
+ continue;
463
+ }
464
+
465
memcpy(dst, "Id$", 3);
466
dst += 3;
467
len -= dollar + 1 - src;
@@ -514,6 +521,11 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
521
break;
522
}
523
524
+ if (memchr(src + 3, '\n', dollar - src - 3)) {
525
+ /* Line break before the next dollar. */
526
+ continue;
527
+ }
528
+
529
len -= dollar + 1 - src;
530
src = dollar + 1;
531
} else {
t/t0021-conversion.sh
+10
-6
@@ -65,17 +65,21 @@ test_expect_success expanded_in_repo '
65
echo "\$Id:NoSpaceAtFront \$"
66
echo "\$Id:NoSpaceAtEitherEnd\$"
67
echo "\$Id: NoTerminatingSymbol"
68
+ echo "\$Id: Foreign Commit With Spaces \$"
69
+ echo "\$Id: NoTerminatingSymbolAtEOF"
70
} > expanded-keywords &&
71
72
{
73
echo "File with expanded keywords"
72
- echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
73
- echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
74
- echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
75
- echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
76
- echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
77
- echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
74
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
75
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
76
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
77
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
78
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
79
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
80
echo "\$Id: NoTerminatingSymbol"
81
+ echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
82
+ echo "\$Id: NoTerminatingSymbolAtEOF"
83
} > expected-output &&
84
85
git add expanded-keywords &&