diff: avoid stack-buffer-read-overrun for very long name
Due to the use of strncpy without explicit NUL termination, we could end up passing names n1 or n2 that are not NUL-terminated to queue_diff, which requires NUL-terminated strings. Ensure that each is NUL terminated. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jim Meyering committed
Apr 16, 2012 at 17:20 UTC
48e510b6a29b1066016cbbee75c0b196174a88d4
1 file changed
+2
diff-no-index.c
+2
@@ -109,6 +109,7 @@ static int queue_diff(struct diff_options *o,
109
n1 = buffer1;
110
strncpy(buffer1 + len1, p1.items[i1++].string,
111
PATH_MAX - len1);
112
+ buffer1[PATH_MAX-1] = 0;
113
}
114
115
if (comp < 0)
@@ -117,6 +118,7 @@ static int queue_diff(struct diff_options *o,
118
n2 = buffer2;
119
strncpy(buffer2 + len2, p2.items[i2++].string,
120
PATH_MAX - len2);
121
+ buffer2[PATH_MAX-1] = 0;
122
}
123
124
ret = queue_diff(o, n1, n2);