Skip to content

Commit cf9196b

Browse files
committed
Tolerate readlink size less than st_size
1 parent 1ee3c37 commit cf9196b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/odb.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,15 @@ int git_odb__hashlink(git_oid *out, const char *path)
297297
GIT_ERROR_CHECK_ALLOC(link_data);
298298

299299
read_len = p_readlink(path, link_data, size);
300-
link_data[size] = '\0';
301-
if (read_len != size) {
300+
if (read_len == -1) {
302301
git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", path);
303302
git__free(link_data);
304303
return -1;
305304
}
305+
GIT_ASSERT(read_len <= size);
306+
link_data[read_len] = '\0';
306307

307-
result = git_odb_hash(out, link_data, size, GIT_OBJECT_BLOB);
308+
result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB);
308309
git__free(link_data);
309310
} else {
310311
int fd = git_futils_open_ro(path);

0 commit comments

Comments
 (0)