Skip to content

Commit 958a478

Browse files
raalkmlgitster
authored andcommitted
Fix potentially dangerous use of git_path in ref.c
Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe2d777 commit 958a478

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

refs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,15 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
401401
*flag = 0;
402402

403403
for (;;) {
404-
const char *path = git_path("%s", ref);
404+
char path[PATH_MAX];
405405
struct stat st;
406406
char *buf;
407407
int fd;
408408

409409
if (--depth < 0)
410410
return NULL;
411411

412+
git_snpath(path, sizeof(path), "%s", ref);
412413
/* Special case: non-existing file.
413414
* Not having the refs/heads/new-branch is OK
414415
* 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,
11211122
int logfd, written, oflags = O_APPEND | O_WRONLY;
11221123
unsigned maxlen, len;
11231124
int msglen;
1124-
char *log_file, *logrec;
1125+
char log_file[PATH_MAX];
1126+
char *logrec;
11251127
const char *committer;
11261128

11271129
if (log_all_ref_updates < 0)
11281130
log_all_ref_updates = !is_bare_repository();
11291131

1130-
log_file = git_path("logs/%s", ref_name);
1132+
git_snpath(log_file, sizeof(log_file), "logs/%s", ref_name);
11311133

11321134
if (log_all_ref_updates &&
11331135
(!prefixcmp(ref_name, "refs/heads/") ||

0 commit comments

Comments
 (0)