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 <[email protected]>
  • Loading branch information
neerajsi-msft committed Oct 27, 2021
1 parent 08a757b commit 435e1d2
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 @@ -1239,8 +1239,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 435e1d2

Please sign in to comment.