mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-18 14:59:09 +00:00
odb: don't overflow the link path buffer
Allocate a buffer large enough to store the path plus the terminator instead of letting readlink write beyond the end.
This commit is contained in:
parent
1e90ae77c4
commit
e8776d30f7
@ -196,10 +196,11 @@ int git_odb__hashlink(git_oid *out, const char *path)
|
|||||||
char *link_data;
|
char *link_data;
|
||||||
ssize_t read_len;
|
ssize_t read_len;
|
||||||
|
|
||||||
link_data = git__malloc((size_t)size);
|
link_data = git__malloc((size_t)(size + 1));
|
||||||
GITERR_CHECK_ALLOC(link_data);
|
GITERR_CHECK_ALLOC(link_data);
|
||||||
|
|
||||||
read_len = p_readlink(path, link_data, (size_t)(size + 1));
|
read_len = p_readlink(path, link_data, (size_t)size);
|
||||||
|
link_data[size] = '\0';
|
||||||
if (read_len != (ssize_t)size) {
|
if (read_len != (ssize_t)size) {
|
||||||
giterr_set(GITERR_OS, "Failed to read symlink data for '%s'", path);
|
giterr_set(GITERR_OS, "Failed to read symlink data for '%s'", path);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user