Merge branch 'ar/mksnpath'
* ar/mksnpath: Use git_pathdup instead of xstrdup(git_path(...)) git_pathdup: returns xstrdup-ed copy of the formatted path Fix potentially dangerous use of git_path in ref.c Add git_snpath: a .git path formatting routine with output buffer Fix potentially dangerous uses of mkpath and git_path Fix potentially dangerous uses of mkpath and git_path Fix mkpath abuse in dwim_ref and dwim_log of sha1_name.c Add mksnpath which allows you to specify the output buffer Conflicts: builtin-revert.c
This commit is contained in:
10
refs.c
10
refs.c
@ -413,7 +413,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
|
||||
*flag = 0;
|
||||
|
||||
for (;;) {
|
||||
const char *path = git_path("%s", ref);
|
||||
char path[PATH_MAX];
|
||||
struct stat st;
|
||||
char *buf;
|
||||
int fd;
|
||||
@ -421,6 +421,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
|
||||
if (--depth < 0)
|
||||
return NULL;
|
||||
|
||||
git_snpath(path, sizeof(path), "%s", ref);
|
||||
/* Special case: non-existing file. */
|
||||
if (lstat(path, &st) < 0) {
|
||||
struct ref_list *list = get_packed_refs();
|
||||
@ -1142,13 +1143,14 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
|
||||
int logfd, written, oflags = O_APPEND | O_WRONLY;
|
||||
unsigned maxlen, len;
|
||||
int msglen;
|
||||
char *log_file, *logrec;
|
||||
char log_file[PATH_MAX];
|
||||
char *logrec;
|
||||
const char *committer;
|
||||
|
||||
if (log_all_ref_updates < 0)
|
||||
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 &&
|
||||
(!prefixcmp(ref_name, "refs/heads/") ||
|
||||
@ -1277,7 +1279,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
|
||||
const char *lockpath;
|
||||
char ref[1000];
|
||||
int fd, len, written;
|
||||
char *git_HEAD = xstrdup(git_path("%s", ref_target));
|
||||
char *git_HEAD = git_pathdup("%s", ref_target);
|
||||
unsigned char old_sha1[20], new_sha1[20];
|
||||
|
||||
if (logmsg && read_ref(ref_target, old_sha1))
|
||||
|
||||
Reference in New Issue
Block a user