提交 fdf72966 编写于 作者: J Jeff King 提交者: Junio C Hamano

probe_utf8_pathname_composition: use internal strbuf

When we are initializing a .git directory, we may call
probe_utf8_pathname_composition to detect utf8 mangling. We
pass in a path buffer for it to use, and it blindly
strcpy()s into it, not knowing whether the buffer is large
enough to hold the result or not.

In practice this isn't a big deal, because the buffer we
pass in already contains "$GIT_DIR/config", and we append
only a few extra bytes to it. But we can easily do the right
thing just by calling git_path_buf ourselves. Technically
this results in a different pathname (before we appended our
utf8 characters to the "config" path, and now they get their
own files in $GIT_DIR), but that should not matter for our
purposes.
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 e2b021eb
...@@ -312,7 +312,7 @@ static int create_default_files(const char *template_path) ...@@ -312,7 +312,7 @@ static int create_default_files(const char *template_path)
strcpy(path + len, "CoNfIg"); strcpy(path + len, "CoNfIg");
if (!access(path, F_OK)) if (!access(path, F_OK))
git_config_set("core.ignorecase", "true"); git_config_set("core.ignorecase", "true");
probe_utf8_pathname_composition(path, len); probe_utf8_pathname_composition();
} }
return reinit; return reinit;
......
...@@ -36,24 +36,26 @@ static size_t has_non_ascii(const char *s, size_t maxlen, size_t *strlen_c) ...@@ -36,24 +36,26 @@ static size_t has_non_ascii(const char *s, size_t maxlen, size_t *strlen_c)
} }
void probe_utf8_pathname_composition(char *path, int len) void probe_utf8_pathname_composition(void)
{ {
struct strbuf path = STRBUF_INIT;
static const char *auml_nfc = "\xc3\xa4"; static const char *auml_nfc = "\xc3\xa4";
static const char *auml_nfd = "\x61\xcc\x88"; static const char *auml_nfd = "\x61\xcc\x88";
int output_fd; int output_fd;
if (precomposed_unicode != -1) if (precomposed_unicode != -1)
return; /* We found it defined in the global config, respect it */ return; /* We found it defined in the global config, respect it */
strcpy(path + len, auml_nfc); git_path_buf(&path, "%s", auml_nfc);
output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600); output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd >= 0) { if (output_fd >= 0) {
close(output_fd); close(output_fd);
strcpy(path + len, auml_nfd); git_path_buf(&path, "%s", auml_nfd);
precomposed_unicode = access(path, R_OK) ? 0 : 1; precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false"); git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
strcpy(path + len, auml_nfc); git_path_buf(&path, "%s", auml_nfc);
if (unlink(path)) if (unlink(path.buf))
die_errno(_("failed to unlink '%s'"), path); die_errno(_("failed to unlink '%s'"), path.buf);
} }
strbuf_release(&path);
} }
......
...@@ -27,7 +27,7 @@ typedef struct { ...@@ -27,7 +27,7 @@ typedef struct {
} PREC_DIR; } PREC_DIR;
void precompose_argv(int argc, const char **argv); void precompose_argv(int argc, const char **argv);
void probe_utf8_pathname_composition(char *, int); void probe_utf8_pathname_composition(void);
PREC_DIR *precompose_utf8_opendir(const char *dirname); PREC_DIR *precompose_utf8_opendir(const char *dirname);
struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *dirp); struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *dirp);
......
...@@ -229,7 +229,7 @@ typedef unsigned long uintptr_t; ...@@ -229,7 +229,7 @@ typedef unsigned long uintptr_t;
#else #else
#define precompose_str(in,i_nfd2nfc) #define precompose_str(in,i_nfd2nfc)
#define precompose_argv(c,v) #define precompose_argv(c,v)
#define probe_utf8_pathname_composition(a,b) #define probe_utf8_pathname_composition()
#endif #endif
#ifdef MKDIR_WO_TRAILING_SLASH #ifdef MKDIR_WO_TRAILING_SLASH
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册