From b95b626e5d422aaf5220337f8b5c7e603ca22423 Mon Sep 17 00:00:00 2001 From: "Neeraj K. Singh" Date: Wed, 27 Oct 2021 14:22:42 -0700 Subject: [PATCH] mingw: do not call xutftowcs_path in mingw_mktemp The `xutftowcs_path` function canonicalizes absolute paths using GetFullPathNameW. This canonicalization may change the length of the string (e.g. getting rid of \.\), which breaks callers that pass the template string in a strbuf and expect the length of the string to remain the same. In my particular case, the tmp-objdir code is passing a strbuf to mkdtemp and is breaking since the strbuf.len is no longer synchronized with strlen(strbuf.buf). Signed-off-by: Neeraj K. Singh Signed-off-by: Johannes Schindelin --- compat/mingw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 1d67646b0be7d6..7b47be7d7650eb 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1278,8 +1278,11 @@ char *mingw_mktemp(char *template) int offset = 0; /* we need to return the path, thus no long paths here! */ - if (xutftowcs_path(wtemplate, template) < 0) + if (xutftowcsn(wtemplate, template, MAX_PATH, -1) < 0) { + if (errno == ERANGE) + errno = ENAMETOOLONG; return NULL; + } if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) && iswalpha(wtemplate[0]) && wtemplate[1] == L':') {