提交 958a4789 编写于 作者: A Alex Riesen 提交者: Junio C Hamano

Fix potentially dangerous use of git_path in ref.c

Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 fe2d7776
...@@ -401,7 +401,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int * ...@@ -401,7 +401,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
*flag = 0; *flag = 0;
for (;;) { for (;;) {
const char *path = git_path("%s", ref); char path[PATH_MAX];
struct stat st; struct stat st;
char *buf; char *buf;
int fd; int fd;
...@@ -409,6 +409,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int * ...@@ -409,6 +409,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
if (--depth < 0) if (--depth < 0)
return NULL; return NULL;
git_snpath(path, sizeof(path), "%s", ref);
/* Special case: non-existing file. /* Special case: non-existing file.
* Not having the refs/heads/new-branch is OK * Not having the refs/heads/new-branch is OK
* if we are writing into it, so is .git/HEAD * if we are writing into it, so is .git/HEAD
...@@ -1121,13 +1122,14 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, ...@@ -1121,13 +1122,14 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
int logfd, written, oflags = O_APPEND | O_WRONLY; int logfd, written, oflags = O_APPEND | O_WRONLY;
unsigned maxlen, len; unsigned maxlen, len;
int msglen; int msglen;
char *log_file, *logrec; char log_file[PATH_MAX];
char *logrec;
const char *committer; const char *committer;
if (log_all_ref_updates < 0) if (log_all_ref_updates < 0)
log_all_ref_updates = !is_bare_repository(); log_all_ref_updates = !is_bare_repository();
log_file = git_path("logs/%s", ref_name); git_snpath(log_file, sizeof(log_file), "logs/%s", ref_name);
if (log_all_ref_updates && if (log_all_ref_updates &&
(!prefixcmp(ref_name, "refs/heads/") || (!prefixcmp(ref_name, "refs/heads/") ||
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册