Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2023-01-13 00:15:52 +0300
committerStan Hu <stanhu@gmail.com>2023-01-13 00:15:52 +0300
commitcefe00a120e9b68f32ac7cd9c15da5eb204c70f6 (patch)
treea1082655b5be1b4d2d4a240c4f4de783f239eeec /cmd
parentc5cdbb65f18508d34910e93f57c2fcc8cd8e2029 (diff)
conflicts: Fix memory corruption in resolving conflicts
git2go's `OdbObject` Data() returns a slice pointing to unmanaged object memory and requires that a reference be held as long as the slice is used. However, we currently don't guarantee that the blob sticks around, and we've seen seg faults in production. To avoid memory corruption, copy the data out into the conflict structure. Relates to https://gitlab.com/gitlab-org/gitaly/-/issues/4720 Changelog: fixed
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gitaly-git2go/resolve_conflicts.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/cmd/gitaly-git2go/resolve_conflicts.go b/cmd/gitaly-git2go/resolve_conflicts.go
index 8169410ec..d8002e31b 100644
--- a/cmd/gitaly-git2go/resolve_conflicts.go
+++ b/cmd/gitaly-git2go/resolve_conflicts.go
@@ -231,10 +231,14 @@ func readConflictEntries(odb *git.Odb, c git.IndexConflict) (*conflict.Entry, *c
return nil, nil, nil, err
}
+ data := blob.Data()
+ contents := make([]byte, len(data))
+ copy(contents, data)
+
*part.result = &conflict.Entry{
Path: part.entry.Path,
Mode: uint(part.entry.Mode),
- Contents: blob.Data(),
+ Contents: contents,
}
}