Skip to content

Commit a2faf0c

Browse files
committed
index: fix use-after-free in add_conflict()
IndexEntry._to_c() returns both the git_index_entry struct and the CFFI-allocated char[] that centry.path points to. add_conflict() was discarding the char[] reference with `_`, so CFFI freed the path string while centry.path still pointed to it. When git_index_conflict_add() read the dangling pointer, it copied garbage into the index (observed as EEEE... on hardened allocators). Keep the path references alive until after the C function returns. Fixes #1417
1 parent 5acab24 commit a2faf0c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

pygit2/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ def add_conflict(
255255
centry_ours: ffi.NULL_TYPE | ffi.GitIndexEntryC = ffi.NULL
256256
centry_theirs: ffi.NULL_TYPE | ffi.GitIndexEntryC = ffi.NULL
257257
if ancestor is not None:
258-
centry_ancestor, _ = ancestor._to_c()
258+
centry_ancestor, path_ancestor = ancestor._to_c()
259259
if ours is not None:
260-
centry_ours, _ = ours._to_c()
260+
centry_ours, path_ours = ours._to_c()
261261
if theirs is not None:
262-
centry_theirs, _ = theirs._to_c()
262+
centry_theirs, path_theirs = theirs._to_c()
263263
err = C.git_index_conflict_add(
264264
self._index, centry_ancestor, centry_ours, centry_theirs
265265
)

0 commit comments

Comments
 (0)