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

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-09-16 02:10:07 +0400
committerCarlos Martín Nieto <carlos@cmartin.tk>2012-09-16 02:10:07 +0400
commite8776d30f7edb570f435cf746d712c696b862bdd (patch)
tree25e65bfd3fc79d3c30c7555ee1817d391a5b854a /src/odb.c
parent1e90ae77c4660f9637125a9f72336a25de817efb (diff)
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.
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/odb.c b/src/odb.c
index 29c56a5bf..d1ffff652 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -196,10 +196,11 @@ int git_odb__hashlink(git_oid *out, const char *path)
char *link_data;
ssize_t read_len;
- link_data = git__malloc((size_t)size);
+ link_data = git__malloc((size_t)(size + 1));
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) {
giterr_set(GITERR_OS, "Failed to read symlink data for '%s'", path);
return -1;