summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-05-30 10:42:25 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2021-06-30 08:58:13 -0500
commit5f7df15de5d93b2477ca07b938b94f4734bfc3ed (patch)
treeeee0b64b3bdd7bc80edc6920f0e4cba7235e3def
parentc78c7ee615c6c921f67c7f3b743d1bb77d6c18e0 (diff)
downloadlibgit2-5f7df15de5d93b2477ca07b938b94f4734bfc3ed.tar.gz
Tolerate readlink size less than st_size
-rw-r--r--src/odb.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/odb.c b/src/odb.c
index 129a63255..410f77099 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -298,14 +298,15 @@ int git_odb__hashlink(git_oid *out, const char *path)
GIT_ERROR_CHECK_ALLOC(link_data);
read_len = p_readlink(path, link_data, size);
- link_data[size] = '\0';
- if (read_len != size) {
+ if (read_len == -1) {
git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", path);
git__free(link_data);
return -1;
}
+ GIT_ASSERT(read_len <= size);
+ link_data[read_len] = '\0';
- result = git_odb_hash(out, link_data, size, GIT_OBJECT_BLOB);
+ result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB);
git__free(link_data);
} else {
int fd = git_futils_open_ro(path);