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>
This commit is contained in:
committed by
Junio C Hamano
parent
b9aa901856
commit
a9f3049f6c
12
convert.c
12
convert.c
@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size)
|
|||||||
cnt++;
|
cnt++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (ch == '\n')
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cnt;
|
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);
|
dollar = memchr(src + 3, '$', len - 3);
|
||||||
if (!dollar)
|
if (!dollar)
|
||||||
break;
|
break;
|
||||||
|
if (memchr(src + 3, '\n', dollar - src - 3)) {
|
||||||
|
/* Line break before the next dollar. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(dst, "Id$", 3);
|
memcpy(dst, "Id$", 3);
|
||||||
dst += 3;
|
dst += 3;
|
||||||
len -= dollar + 1 - src;
|
len -= dollar + 1 - src;
|
||||||
@ -514,6 +521,11 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (memchr(src + 3, '\n', dollar - src - 3)) {
|
||||||
|
/* Line break before the next dollar. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
len -= dollar + 1 - src;
|
len -= dollar + 1 - src;
|
||||||
src = dollar + 1;
|
src = dollar + 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -65,17 +65,21 @@ test_expect_success expanded_in_repo '
|
|||||||
echo "\$Id:NoSpaceAtFront \$"
|
echo "\$Id:NoSpaceAtFront \$"
|
||||||
echo "\$Id:NoSpaceAtEitherEnd\$"
|
echo "\$Id:NoSpaceAtEitherEnd\$"
|
||||||
echo "\$Id: NoTerminatingSymbol"
|
echo "\$Id: NoTerminatingSymbol"
|
||||||
|
echo "\$Id: Foreign Commit With Spaces \$"
|
||||||
|
echo "\$Id: NoTerminatingSymbolAtEOF"
|
||||||
} > expanded-keywords &&
|
} > expanded-keywords &&
|
||||||
|
|
||||||
{
|
{
|
||||||
echo "File with expanded keywords"
|
echo "File with expanded keywords"
|
||||||
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
echo "\$Id: NoTerminatingSymbol"
|
echo "\$Id: NoTerminatingSymbol"
|
||||||
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
||||||
|
echo "\$Id: NoTerminatingSymbolAtEOF"
|
||||||
} > expected-output &&
|
} > expected-output &&
|
||||||
|
|
||||||
git add expanded-keywords &&
|
git add expanded-keywords &&
|
||||||
|
|||||||
Reference in New Issue
Block a user