Skip to content

Commit

Permalink
mingw: do not call xutftowcs_path in mingw_mktemp
Browse files Browse the repository at this point in the history
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 <neerajsi@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
neerajsi-msft authored and dscho committed Sep 24, 2024
1 parent dc6fbc7 commit a34a4d3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,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':') {
Expand Down

0 comments on commit a34a4d3

Please sign in to comment.