Skip to content

Commit f1c7a0e

Browse files
Kevin Willforddscho
authored andcommitted
name-hash: fix buffer overrun
Add check for the end of the entries for the thread partition. Add test for lazy init name hash with specific directory structure The lazy init hash name was causing a buffer overflow when the last entry in the index was multiple folder deep with parent folders that did not have any files in them. This adds a test for the boundary condition of the thread partitions with the folder structure that was triggering the buffer overflow. The fix was to check if it is the last entry for the thread partition in the handle_range_dir and not try to use the next entry in the cache. Signed-off-by: Kevin Willford <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7235d45 commit f1c7a0e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

name-hash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ static int handle_range_dir(
342342
* Scan forward in the index array for index entries having the same
343343
* path prefix (that are also in this directory).
344344
*/
345-
if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
345+
if (k_start + 1 >= k_end)
346+
k = k_end;
347+
else if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
346348
k = k_start + 1;
347349
else if (strncmp(istate->cache[k_end - 1]->name, prefix->buf, prefix->len) == 0)
348350
k = k_end;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
test_description='Test the lazy init name hash with various folder structures'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'no buffer overflow in lazy_init_name_hash' '
8+
(
9+
test_seq 2000 | sed "s/^/a_/"
10+
echo b/b/b
11+
test_seq 2000 | sed "s/^/c_/"
12+
test_seq 50 | sed "s/^/d_/" | tr "\n" "/"; echo d
13+
) |
14+
sed -e "s/^/100644 $EMPTY_BLOB /" |
15+
git update-index --index-info &&
16+
test-lazy-init-name-hash -m
17+
'
18+
19+
test_done

0 commit comments

Comments
 (0)