Skip to content

Commit 07f546c

Browse files
vegardgitster
authored andcommitted
line-log: use COPY_ARRAY to fix mis-sized memcpy
This memcpy meant to get the sizeof a "struct range", not a "range_set", as the former is what our array holds. Rather than swap out the types, let's convert this site to COPY_ARRAY, which avoids the problem entirely (and confirms that the src and dst types match). Note for curiosity's sake that this bug doesn't trigger on I32LP64 systems, but does on ILP32 systems. The mistaken "struct range_set" has two ints and a pointer. That's 16 bytes on LP64, or 12 on ILP32. The correct "struct range" type has two longs, which is also 16 on LP64, but only 8 on ILP32. Likewise an IL32P64 system would experience the bug. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Vegard Nossum <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3808ca commit 07f546c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

line-log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ void range_set_release(struct range_set *rs)
4343
static void range_set_copy(struct range_set *dst, struct range_set *src)
4444
{
4545
range_set_init(dst, src->nr);
46-
memcpy(dst->ranges, src->ranges, src->nr*sizeof(struct range_set));
46+
COPY_ARRAY(dst->ranges, src->ranges, src->nr);
4747
dst->nr = src->nr;
4848
}
49+
4950
static void range_set_move(struct range_set *dst, struct range_set *src)
5051
{
5152
range_set_release(dst);

0 commit comments

Comments
 (0)