summaryrefslogtreecommitdiff
path: root/compat/precompose_utf8.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-10-04 23:45:26 -0400
committerJunio C Hamano <gitster@pobox.com>2015-10-05 11:06:49 -0700
commitfdf729661a777d8bd598f40055d92b2df5601332 (patch)
treef550af4a1bab89529aa73accc8e08a6a43b2f3a3 /compat/precompose_utf8.c
parente2b021eb5b5ce2f4be3c10f1f8063981b1a53053 (diff)
downloadgit-fdf729661a777d8bd598f40055d92b2df5601332.tar.gz
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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/precompose_utf8.c')
-rw-r--r--compat/precompose_utf8.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 044c68617b..079070ff1d 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.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_nfd = "\x61\xcc\x88";
int output_fd;
if (precomposed_unicode != -1)
return; /* We found it defined in the global config, respect it */
- strcpy(path + len, auml_nfc);
- output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600);
+ git_path_buf(&path, "%s", auml_nfc);
+ output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd >= 0) {
close(output_fd);
- strcpy(path + len, auml_nfd);
- precomposed_unicode = access(path, R_OK) ? 0 : 1;
+ git_path_buf(&path, "%s", auml_nfd);
+ precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
- strcpy(path + len, auml_nfc);
- if (unlink(path))
- die_errno(_("failed to unlink '%s'"), path);
+ git_path_buf(&path, "%s", auml_nfc);
+ if (unlink(path.buf))
+ die_errno(_("failed to unlink '%s'"), path.buf);
}
+ strbuf_release(&path);
}