зеркало из https://github.com/microsoft/git.git
Merge branch 'ar/maint-mksnpath' into ar/mksnpath
* ar/maint-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 Conflicts: builtin-revert.c refs.c rerere.c
This commit is contained in:
Коммит
98b35e2c74
|
@ -84,7 +84,7 @@ static int get_value(const char* key_, const char* regex_)
|
|||
local = config_exclusive_filename;
|
||||
if (!local) {
|
||||
const char *home = getenv("HOME");
|
||||
local = repo_config = xstrdup(git_path("config"));
|
||||
local = repo_config = git_pathdup("config");
|
||||
if (git_config_global() && home)
|
||||
global = xstrdup(mkpath("%s/.gitconfig", home));
|
||||
if (git_config_system())
|
||||
|
|
|
@ -277,11 +277,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
|
|||
lock = lock_any_ref_for_update(ref, sha1, 0);
|
||||
if (!lock)
|
||||
return error("cannot lock ref '%s'", ref);
|
||||
log_file = xstrdup(git_path("logs/%s", ref));
|
||||
log_file = git_pathdup("logs/%s", ref);
|
||||
if (!file_exists(log_file))
|
||||
goto finish;
|
||||
if (!cmd->dry_run) {
|
||||
newlog_path = xstrdup(git_path("logs/%s.lock", ref));
|
||||
newlog_path = git_pathdup("logs/%s.lock", ref);
|
||||
cb.newlog = fopen(newlog_path, "w");
|
||||
}
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
|
|||
int i, index_fd, clean;
|
||||
char *oneline, *reencoded_message = NULL;
|
||||
const char *message, *encoding;
|
||||
const char *defmsg = xstrdup(git_path("MERGE_MSG"));
|
||||
const char *defmsg = git_pathdup("MERGE_MSG");
|
||||
struct merge_options o;
|
||||
struct tree *result, *next_tree, *base_tree, *head_tree;
|
||||
static struct lock_file index_lock;
|
||||
|
|
|
@ -283,7 +283,7 @@ static void create_tag(const unsigned char *object, const char *tag,
|
|||
int fd;
|
||||
|
||||
/* write the template message before editing: */
|
||||
path = xstrdup(git_path("TAG_EDITMSG"));
|
||||
path = git_pathdup("TAG_EDITMSG");
|
||||
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
|
||||
if (fd < 0)
|
||||
die("could not create file '%s': %s",
|
||||
|
|
4
cache.h
4
cache.h
|
@ -497,6 +497,10 @@ extern int check_repository_format(void);
|
|||
|
||||
extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
||||
__attribute__((format (printf, 3, 4)));
|
||||
extern char *git_snpath(char *buf, size_t n, const char *fmt, ...)
|
||||
__attribute__((format (printf, 3, 4)));
|
||||
extern char *git_pathdup(const char *fmt, ...)
|
||||
__attribute__((format (printf, 1, 2)));
|
||||
|
||||
/* Return a statically allocated filename matching the sha1 signature */
|
||||
extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
|
||||
|
|
6
config.c
6
config.c
|
@ -649,7 +649,7 @@ int git_config(config_fn_t fn, void *data)
|
|||
free(user_config);
|
||||
}
|
||||
|
||||
repo_config = xstrdup(git_path("config"));
|
||||
repo_config = git_pathdup("config");
|
||||
ret += git_config_from_file(fn, repo_config, data);
|
||||
free(repo_config);
|
||||
return ret;
|
||||
|
@ -889,7 +889,7 @@ int git_config_set_multivar(const char* key, const char* value,
|
|||
if (config_exclusive_filename)
|
||||
config_filename = xstrdup(config_exclusive_filename);
|
||||
else
|
||||
config_filename = xstrdup(git_path("config"));
|
||||
config_filename = git_pathdup("config");
|
||||
|
||||
/*
|
||||
* Since "key" actually contains the section name and the real
|
||||
|
@ -1149,7 +1149,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
|
|||
if (config_exclusive_filename)
|
||||
config_filename = xstrdup(config_exclusive_filename);
|
||||
else
|
||||
config_filename = xstrdup(git_path("config"));
|
||||
config_filename = git_pathdup("config");
|
||||
out_fd = hold_lock_file_for_update(lock, config_filename, 0);
|
||||
if (out_fd < 0) {
|
||||
ret = error("could not lock config file %s", config_filename);
|
||||
|
|
|
@ -71,7 +71,7 @@ static void setup_git_env(void)
|
|||
}
|
||||
git_graft_file = getenv(GRAFT_ENVIRONMENT);
|
||||
if (!git_graft_file)
|
||||
git_graft_file = xstrdup(git_path("info/grafts"));
|
||||
git_graft_file = git_pathdup("info/grafts");
|
||||
}
|
||||
|
||||
int is_bare_repository(void)
|
||||
|
|
39
path.c
39
path.c
|
@ -47,6 +47,45 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
|||
return cleanup_path(buf);
|
||||
}
|
||||
|
||||
static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args)
|
||||
{
|
||||
const char *git_dir = get_git_dir();
|
||||
size_t len;
|
||||
|
||||
len = strlen(git_dir);
|
||||
if (n < len + 1)
|
||||
goto bad;
|
||||
memcpy(buf, git_dir, len);
|
||||
if (len && !is_dir_sep(git_dir[len-1]))
|
||||
buf[len++] = '/';
|
||||
len += vsnprintf(buf + len, n - len, fmt, args);
|
||||
if (len >= n)
|
||||
goto bad;
|
||||
return cleanup_path(buf);
|
||||
bad:
|
||||
snprintf(buf, n, bad_path);
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *git_snpath(char *buf, size_t n, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
(void)git_vsnpath(buf, n, fmt, args);
|
||||
va_end(args);
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *git_pathdup(const char *fmt, ...)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
(void)git_vsnpath(path, sizeof(path), fmt, args);
|
||||
va_end(args);
|
||||
return xstrdup(path);
|
||||
}
|
||||
|
||||
char *mkpath(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
|
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();
|
||||
|
@ -1130,13 +1131,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/") ||
|
||||
|
@ -1265,7 +1267,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))
|
||||
|
|
2
rerere.c
2
rerere.c
|
@ -351,7 +351,7 @@ int setup_rerere(struct string_list *merge_rr)
|
|||
if (!is_rerere_enabled())
|
||||
return -1;
|
||||
|
||||
merge_rr_path = xstrdup(git_path("MERGE_RR"));
|
||||
merge_rr_path = git_pathdup("MERGE_RR");
|
||||
fd = hold_lock_file_for_update(&write_lock, merge_rr_path,
|
||||
LOCK_DIE_ON_ERROR);
|
||||
read_rr(merge_rr);
|
||||
|
|
|
@ -25,7 +25,7 @@ static int add_info_ref(const char *path, const unsigned char *sha1, int flag, v
|
|||
|
||||
static int update_info_refs(int force)
|
||||
{
|
||||
char *path0 = xstrdup(git_path("info/refs"));
|
||||
char *path0 = git_pathdup("info/refs");
|
||||
int len = strlen(path0);
|
||||
char *path1 = xmalloc(len + 2);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче