Fix potentially dangerous use of git_path in ref.c
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alex Riesen committed
Oct 27, 2008 at 11:11 UTC
958a4789e0e74da245175e31bd3b9b354ee0e063
1 file changed
+5
-3
refs.c
+5
-3
@@ -401,7 +401,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
401
*flag = 0;
402
403
for (;;) {
404
- const char *path = git_path("%s", ref);
404
+ char path[PATH_MAX];
405
struct stat st;
406
char *buf;
407
int fd;
@@ -409,6 +409,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
409
if (--depth < 0)
410
return NULL;
411
412
+ git_snpath(path, sizeof(path), "%s", ref);
413
/* Special case: non-existing file.
414
* Not having the refs/heads/new-branch is OK
415
* 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,
1122
int logfd, written, oflags = O_APPEND | O_WRONLY;
1123
unsigned maxlen, len;
1124
int msglen;
1124
- char *log_file, *logrec;
1125
+ char log_file[PATH_MAX];
1126
+ char *logrec;
1127
const char *committer;
1128
1129
if (log_all_ref_updates < 0)
1130
log_all_ref_updates = !is_bare_repository();
1131
1130
- log_file = git_path("logs/%s", ref_name);
1132
+ git_snpath(log_file, sizeof(log_file), "logs/%s", ref_name);
1133
1134
if (log_all_ref_updates &&
1135
(!prefixcmp(ref_name, "refs/heads/") ||