提交 228740b6 编写于 作者: J Jeff King 提交者: Junio C Hamano

worktree: use xsize_t to access file size

To read the "gitdir" file into memory, we stat the file and
allocate a buffer. But we store the size in an "int", which
may be truncated. We should use a size_t and xsize_t(),
which will detect truncation.

An overflow is unlikely for a "gitdir" file, but it's a good
practice to model.
Signed-off-by: NJeff King <peff@peff.net>
Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 41dcc4dc
......@@ -38,7 +38,8 @@ static int prune_worktree(const char *id, struct strbuf *reason)
{
struct stat st;
char *path;
int fd, len;
int fd;
size_t len;
if (!is_directory(git_path("worktrees/%s", id))) {
strbuf_addf(reason, _("Removing worktrees/%s: not a valid directory"), id);
......@@ -56,7 +57,7 @@ static int prune_worktree(const char *id, struct strbuf *reason)
id, strerror(errno));
return 1;
}
len = st.st_size;
len = xsize_t(st.st_size);
path = xmallocz(len);
read_in_full(fd, path, len);
close(fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册