Skip to content

Commit 48e510b

Browse files
meyeringgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6eab5f2 commit 48e510b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

diff-no-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static int queue_diff(struct diff_options *o,
109109
n1 = buffer1;
110110
strncpy(buffer1 + len1, p1.items[i1++].string,
111111
PATH_MAX - len1);
112+
buffer1[PATH_MAX-1] = 0;
112113
}
113114

114115
if (comp < 0)
@@ -117,6 +118,7 @@ static int queue_diff(struct diff_options *o,
117118
n2 = buffer2;
118119
strncpy(buffer2 + len2, p2.items[i2++].string,
119120
PATH_MAX - len2);
121+
buffer2[PATH_MAX-1] = 0;
120122
}
121123

122124
ret = queue_diff(o, n1, n2);

0 commit comments

Comments
 (0)