Skip to content

Commit ef6a2a9

Browse files
committed
Merge branch 'wcstombs'
This topic branch fixes the problem where a UTF-16 command-line was converted to UTF-8 in an incorrect way (because Cygwin treated it as if it was a file name and applied some magic that is intended to allow for otherwise invalid file names on Windows). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 96e0bad + 8095a41 commit ef6a2a9

14 files changed

+62
-56
lines changed

winsup/cygwin/dcrt0.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,9 @@ dll_crt0_1 (void *)
935935
if (!__argc)
936936
{
937937
PWCHAR wline = GetCommandLineW ();
938-
size_t size = sys_wcstombs_no_path (NULL, 0, wline) + 1;
938+
size_t size = sys_wcstombs (NULL, 0, wline) + 1;
939939
char *line = (char *) alloca (size);
940-
sys_wcstombs_no_path (line, size, wline);
940+
sys_wcstombs (line, size, wline);
941941

942942
/* Scan the command line and build argv. Expand wildcards if not
943943
called from another cygwin process. */

winsup/cygwin/dtable.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ handle_to_fn (HANDLE h, char *posix_fn)
995995
if (wcsncasecmp (w32, DEVICE_PREFIX, DEVICE_PREFIX_LEN) != 0
996996
|| !QueryDosDeviceW (NULL, fnbuf, sizeof (fnbuf) / sizeof (WCHAR)))
997997
{
998-
sys_wcstombs (posix_fn, NT_MAX_PATH, w32, w32len);
998+
sys_wcstombs_path (posix_fn, NT_MAX_PATH, w32, w32len);
999999
return false;
10001000
}
10011001

winsup/cygwin/environ.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ win32env_to_cygenv (PWCHAR rawenv, bool posify)
869869
eventually want to use them). */
870870
for (i = 0, w = rawenv; *w != L'\0'; w = wcschr (w, L'\0') + 1, i++)
871871
{
872-
sys_wcstombs_alloc_no_path (&newp, HEAP_NOTHEAP, w);
872+
sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w);
873873
if (i >= envc)
874874
envp = (char **) realloc (envp, (4 + (envc += 100)) * sizeof (char *));
875875
envp[i] = newp;
@@ -927,15 +927,15 @@ getwinenveq (const char *name, size_t namelen, int x)
927927
int totlen = GetEnvironmentVariableW (name0, valbuf, 32768);
928928
if (totlen > 0)
929929
{
930-
totlen = sys_wcstombs_no_path (NULL, 0, valbuf) + 1;
930+
totlen = sys_wcstombs (NULL, 0, valbuf) + 1;
931931
if (x == HEAP_1_STR)
932932
totlen += namelen;
933933
else
934934
namelen = 0;
935935
char *p = (char *) cmalloc_abort ((cygheap_types) x, totlen);
936936
if (namelen)
937937
strcpy (p, name);
938-
sys_wcstombs_no_path (p + namelen, totlen, valbuf);
938+
sys_wcstombs (p + namelen, totlen, valbuf);
939939
debug_printf ("using value from GetEnvironmentVariable for '%W'", name0);
940940
return p;
941941
}
@@ -1088,7 +1088,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
10881088
for (winnum = 0, var = cwinenv;
10891089
*var;
10901090
++winnum, var = wcschr (var, L'\0') + 1)
1091-
sys_wcstombs_alloc_no_path (&winenv[winnum], HEAP_NOTHEAP, var);
1091+
sys_wcstombs_alloc (&winenv[winnum], HEAP_NOTHEAP, var);
10921092
}
10931093
DestroyEnvironmentBlock (cwinenv);
10941094
/* Eliminate variables which are already available in envp, as well as

winsup/cygwin/external.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fillout_pinfo (pid_t pid, int winpid)
8888
ep.rusage_self = p->rusage_self;
8989
ep.rusage_children = p->rusage_children;
9090
ep.progname[0] = '\0';
91-
sys_wcstombs(ep.progname, MAX_PATH, p->progname);
91+
sys_wcstombs_path (ep.progname, MAX_PATH, p->progname);
9292
ep.strace_mask = 0;
9393
ep.version = EXTERNAL_PINFO_VERSION;
9494

winsup/cygwin/fhandler_disk_file.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class __DIR_mounts
5050
char *c = stpcpy (fname, parent_dir);
5151
if (c[- 1] != '/')
5252
*c++ = '/';
53-
sys_wcstombs (c, mounts[idx].Length + 1,
53+
sys_wcstombs_path (c, mounts[idx].Length + 1,
5454
mounts[idx].Buffer, mounts[idx].Length / sizeof (WCHAR));
5555
path_conv pc (fname, PC_SYM_NOFOLLOW | PC_POSIX | PC_KEEP_HANDLE);
5656
if (!stat_worker (pc, &st))
@@ -2057,7 +2057,7 @@ fhandler_disk_file::readdir_helper (DIR *dir, dirent *de, DWORD w32_err,
20572057
char *p = stpcpy (file, pc.get_posix ());
20582058
if (p[-1] != '/')
20592059
*p++ = '/';
2060-
sys_wcstombs (p, NT_MAX_PATH - (p - file),
2060+
sys_wcstombs_path (p, NT_MAX_PATH - (p - file),
20612061
fname->Buffer, fname->Length / sizeof (WCHAR));
20622062
path_conv fpath (file, PC_SYM_NOFOLLOW);
20632063
if (fpath.issymlink ())
@@ -2078,7 +2078,7 @@ fhandler_disk_file::readdir_helper (DIR *dir, dirent *de, DWORD w32_err,
20782078
}
20792079
}
20802080

2081-
sys_wcstombs (de->d_name, NAME_MAX + 1, fname->Buffer,
2081+
sys_wcstombs_path (de->d_name, NAME_MAX + 1, fname->Buffer,
20822082
fname->Length / sizeof (WCHAR));
20832083

20842084
/* Don't try to optimize relative to dir->__d_position. On several

winsup/cygwin/fhandler_netdrive.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ fhandler_netdrive::readdir (DIR *dir, dirent *de)
252252
tp.u_get (&ds);
253253
RtlInitUnicodeString (&ss, bs);
254254
RtlDowncaseUnicodeString (&ds, &ss, FALSE);
255-
sys_wcstombs (de->d_name, sizeof de->d_name,
255+
sys_wcstombs_path (de->d_name, sizeof de->d_name,
256256
ds.Buffer, ds.Length / sizeof (WCHAR));
257257
de->d_ino = hash_path_name (get_ino (), de->d_name);
258258
}
259259
else
260260
{
261-
sys_wcstombs (de->d_name, sizeof de->d_name, bs);
261+
sys_wcstombs_path (de->d_name, sizeof de->d_name, bs);
262262
char *rpath = tp.c_get ();
263-
sys_wcstombs (rpath, NT_MAX_PATH, nro->lpRemoteName);
263+
sys_wcstombs_path (rpath, NT_MAX_PATH, nro->lpRemoteName);
264264
de->d_ino = readdir_get_ino (rpath, false);
265265
/* We can't trust remote inode numbers of only 32 bit. That means,
266266
remote NT4 NTFS, as well as shares of Samba version < 3.0. */

winsup/cygwin/fhandler_process.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,10 @@ static off_t
565565
format_process_winexename (void *data, char *&destbuf)
566566
{
567567
_pinfo *p = (_pinfo *) data;
568-
size_t len = sys_wcstombs (NULL, 0, p->progname);
568+
size_t len = sys_wcstombs_path (NULL, 0, p->progname);
569569
destbuf = (char *) crealloc_abort (destbuf, len + 1);
570570
/* With trailing \0 for backward compat reasons. */
571-
sys_wcstombs (destbuf, len + 1, p->progname);
571+
sys_wcstombs_path (destbuf, len + 1, p->progname);
572572
return len;
573573
}
574574

@@ -1028,7 +1028,7 @@ format_process_maps (void *data, char *&destbuf)
10281028
drive_maps.fixup_if_match (msi->SectionFileName.Buffer);
10291029
if (mount_table->conv_to_posix_path (dosname,
10301030
posix_modname, 0))
1031-
sys_wcstombs (posix_modname, NT_MAX_PATH, dosname);
1031+
sys_wcstombs_path (posix_modname, NT_MAX_PATH, dosname);
10321032
stat64 (posix_modname, &st);
10331033
}
10341034
else if (!threads.fill_if_match (cur.abase, mb.Type,
@@ -1074,7 +1074,7 @@ format_process_stat (void *data, char *&destbuf)
10741074
else
10751075
{
10761076
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
1077-
sys_wcstombs (cmd, NAME_MAX + 1,
1077+
sys_wcstombs_path (cmd, NAME_MAX + 1,
10781078
last_slash ? last_slash + 1 : p->progname);
10791079
int len = strlen (cmd);
10801080
if (len > 4)
@@ -1192,7 +1192,8 @@ format_process_status (void *data, char *&destbuf)
11921192
vmtext = 0UL, vmshare = 0UL;
11931193

11941194
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
1195-
sys_wcstombs (cmd, NAME_MAX + 1, last_slash ? last_slash + 1 : p->progname);
1195+
sys_wcstombs_path (cmd, NAME_MAX + 1,
1196+
last_slash ? last_slash + 1 : p->progname);
11961197
int len = strlen (cmd);
11971198
if (len > 4)
11981199
{

winsup/cygwin/fhandler_procsys.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,11 @@ fhandler_procsys::fill_filebuf ()
241241
NtClose (h);
242242
if (!NT_SUCCESS (status))
243243
goto unreadable;
244-
len = sys_wcstombs (NULL, 0, target.Buffer, target.Length / sizeof (WCHAR));
244+
len = sys_wcstombs_path (NULL, 0,
245+
target.Buffer, target.Length / sizeof (WCHAR));
245246
filebuf = (char *) crealloc_abort (filebuf, procsys_len + len + 1);
246-
sys_wcstombs (fnamep = stpcpy (filebuf, procsys), len + 1, target.Buffer,
247-
target.Length / sizeof (WCHAR));
247+
sys_wcstombs_path (fnamep = stpcpy (filebuf, procsys), len + 1,
248+
target.Buffer, target.Length / sizeof (WCHAR));
248249
while ((fnamep = strchr (fnamep, '\\')))
249250
*fnamep = '/';
250251
return true;
@@ -353,7 +354,7 @@ fhandler_procsys::readdir (DIR *dir, dirent *de)
353354
res = ENMFILE;
354355
else
355356
{
356-
sys_wcstombs (de->d_name, NAME_MAX + 1, f.dbi.ObjectName.Buffer,
357+
sys_wcstombs_path (de->d_name, NAME_MAX + 1, f.dbi.ObjectName.Buffer,
357358
f.dbi.ObjectName.Length / sizeof (WCHAR));
358359
de->d_ino = hash_path_name (get_ino (), de->d_name);
359360
if (RtlEqualUnicodeString (&f.dbi.ObjectTypeName, &ro_u_natdir,

winsup/cygwin/mount.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
436436
{
437437
/* The filesystem name is only used in fillout_mntent and only if
438438
the filesystem isn't one of the well-known filesystems anyway. */
439-
sys_wcstombs (fsn, sizeof fsn, ffai_buf.ffai.FileSystemName,
439+
sys_wcstombs_path (fsn, sizeof fsn, ffai_buf.ffai.FileSystemName,
440440
ffai_buf.ffai.FileSystemNameLength / sizeof (WCHAR));
441441
strlwr (fsn);
442442
}
@@ -463,7 +463,7 @@ mount_info::create_root_entry (const PWCHAR root)
463463
/* Create a default root dir derived from the location of the Cygwin DLL.
464464
The entry is immutable, unless the "override" option is given in /etc/fstab. */
465465
char native_root[PATH_MAX];
466-
sys_wcstombs (native_root, PATH_MAX, root);
466+
sys_wcstombs_path (native_root, PATH_MAX, root);
467467
assert (*native_root != '\0');
468468
if (add_item (native_root, "/",
469469
MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_IMMUTABLE | MOUNT_AUTOMATIC | MOUNT_NOACL)
@@ -859,7 +859,7 @@ mount_info::conv_to_posix_path (PWCHAR src_path, char *posix_path,
859859
}
860860
tmp_pathbuf tp;
861861
char *buf = tp.c_get ();
862-
sys_wcstombs (buf, NT_MAX_PATH, src_path);
862+
sys_wcstombs_path (buf, NT_MAX_PATH, src_path);
863863
int ret = conv_to_posix_path (buf, posix_path, ccp_flags);
864864
if (changed)
865865
src_path[0] = L'C';
@@ -1205,7 +1205,7 @@ mount_info::from_fstab_line (char *line, bool user)
12051205
{
12061206
tmp_pathbuf tp;
12071207
char *mb_tmp = tp.c_get ();
1208-
sys_wcstombs (mb_tmp, PATH_MAX, tmp);
1208+
sys_wcstombs_path (mb_tmp, PATH_MAX, tmp);
12091209

12101210
mount_flags |= MOUNT_USER_TEMP;
12111211
int res = mount_table->add_item (mb_tmp, posix_path, mount_flags);

winsup/cygwin/nlsfuncs.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ internal_setlocale ()
15501550
if (w_path)
15511551
{
15521552
char *c_path = tp.c_get ();
1553-
sys_wcstombs (c_path, 32768, w_path);
1553+
sys_wcstombs_path (c_path, 32768, w_path);
15541554
setenv ("PATH", c_path, 1);
15551555
}
15561556
}

winsup/cygwin/path.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ path_conv::check (const UNICODE_STRING *src, unsigned opt,
642642
char *path = tp.c_get ();
643643

644644
user_shared->warned_msdos = true;
645-
sys_wcstombs (path, NT_MAX_PATH, src->Buffer, src->Length / sizeof (WCHAR));
645+
sys_wcstombs_path (path, NT_MAX_PATH,
646+
src->Buffer, src->Length / sizeof (WCHAR));
646647
path_conv::check (path, opt, suffixes);
647648
}
648649

@@ -2337,7 +2338,7 @@ symlink_info::check_shortcut (HANDLE h)
23372338
if (*(PWCHAR) cp == 0xfeff) /* BOM */
23382339
{
23392340
char *tmpbuf = tp.c_get ();
2340-
if (sys_wcstombs (tmpbuf, NT_MAX_PATH, (PWCHAR) (cp + 2))
2341+
if (sys_wcstombs_path (tmpbuf, NT_MAX_PATH, (PWCHAR) (cp + 2))
23412342
> SYMLINK_MAX)
23422343
return 0;
23432344
res = posixify (tmpbuf);
@@ -2418,7 +2419,7 @@ symlink_info::check_sysfile (HANDLE h)
24182419
else
24192420
srcbuf += 2;
24202421
char *tmpbuf = tp.c_get ();
2421-
if (sys_wcstombs (tmpbuf, NT_MAX_PATH, (PWCHAR) srcbuf)
2422+
if (sys_wcstombs_path (tmpbuf, NT_MAX_PATH, (PWCHAR) srcbuf)
24222423
> SYMLINK_MAX)
24232424
debug_printf ("symlink string too long");
24242425
else
@@ -2505,7 +2506,7 @@ symlink_info::check_reparse_point (HANDLE h, bool remote)
25052506
fileattr &= ~FILE_ATTRIBUTE_REPARSE_POINT;
25062507
return 0;
25072508
}
2508-
sys_wcstombs (srcbuf, SYMLINK_MAX + 7, subst.Buffer,
2509+
sys_wcstombs_path (srcbuf, SYMLINK_MAX + 7, subst.Buffer,
25092510
subst.Length / sizeof (WCHAR));
25102511
pflags |= PATH_SYMLINK | PATH_REP;
25112512
/* A symlink is never a directory. */
@@ -2538,7 +2539,7 @@ symlink_info::check_nfs_symlink (HANDLE h)
25382539
{
25392540
PWCHAR spath = (PWCHAR)
25402541
(pffei->EaName + pffei->EaNameLength + 1);
2541-
res = sys_wcstombs (contents, SYMLINK_MAX + 1,
2542+
res = sys_wcstombs_path (contents, SYMLINK_MAX + 1,
25422543
spath, pffei->EaValueLength);
25432544
pflags |= PATH_SYMLINK;
25442545
}
@@ -3570,7 +3571,7 @@ cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to,
35703571
}
35713572
PUNICODE_STRING up = p.get_nt_native_path ();
35723573
buf = tp.c_get ();
3573-
sys_wcstombs (buf, NT_MAX_PATH,
3574+
sys_wcstombs_path (buf, NT_MAX_PATH,
35743575
up->Buffer, up->Length / sizeof (WCHAR));
35753576
/* Convert native path to standard DOS path. */
35763577
if (!strncmp (buf, "\\??\\", 4))
@@ -3583,11 +3584,11 @@ cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to,
35833584
{
35843585
/* Device name points to somewhere else in the NT namespace.
35853586
Use GLOBALROOT prefix to convert to Win32 path. */
3586-
char *p = buf + sys_wcstombs (buf, NT_MAX_PATH,
3587+
char *p = buf + sys_wcstombs_path (buf, NT_MAX_PATH,
35873588
ro_u_globalroot.Buffer,
35883589
ro_u_globalroot.Length
35893590
/ sizeof (WCHAR));
3590-
sys_wcstombs (p, NT_MAX_PATH - (p - buf),
3591+
sys_wcstombs_path (p, NT_MAX_PATH - (p - buf),
35913592
up->Buffer, up->Length / sizeof (WCHAR));
35923593
}
35933594
lsiz = strlen (buf) + 1;
@@ -3961,8 +3962,8 @@ cygwin_conv_path_list (cygwin_conv_path_t what, const void *from, void *to,
39613962
switch (what & CCP_CONVTYPE_MASK)
39623963
{
39633964
case CCP_WIN_W_TO_POSIX:
3964-
if (!sys_wcstombs_alloc (&winp, HEAP_NOTHEAP, (const wchar_t *) from,
3965-
(size_t) -1))
3965+
if (!sys_wcstombs_alloc_path (&winp, HEAP_NOTHEAP,
3966+
(const wchar_t *) from, (size_t) -1))
39663967
return -1;
39673968
what = (what & ~CCP_CONVTYPE_MASK) | CCP_WIN_A_TO_POSIX;
39683969
from = (const void *) winp;
@@ -4904,9 +4905,9 @@ cwdstuff::get_error_desc () const
49044905
void
49054906
cwdstuff::reset_posix (wchar_t *w_cwd)
49064907
{
4907-
size_t len = sys_wcstombs (NULL, (size_t) -1, w_cwd);
4908+
size_t len = sys_wcstombs_path (NULL, (size_t) -1, w_cwd);
49084909
posix = (char *) crealloc_abort (posix, len + 1);
4909-
sys_wcstombs (posix, len + 1, w_cwd);
4910+
sys_wcstombs_path (posix, len + 1, w_cwd);
49104911
}
49114912

49124913
char *
@@ -4929,7 +4930,7 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen)
49294930
if (!need_posix)
49304931
{
49314932
tocopy = tp.c_get ();
4932-
sys_wcstombs (tocopy, NT_MAX_PATH, win32.Buffer,
4933+
sys_wcstombs_path (tocopy, NT_MAX_PATH, win32.Buffer,
49334934
win32.Length / sizeof (WCHAR));
49344935
}
49354936
else

winsup/cygwin/strfuncs.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,13 @@ sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
490490
}
491491

492492
size_t __reg3
493-
sys_wcstombs (char *dst, size_t len, const wchar_t * src, size_t nwc)
493+
sys_wcstombs_path (char *dst, size_t len, const wchar_t * src, size_t nwc)
494494
{
495495
return sys_wcstombs (dst, len, src, nwc, true);
496496
}
497497

498498
size_t __reg3
499-
sys_wcstombs_no_path (char *dst, size_t len, const wchar_t * src, size_t nwc)
499+
sys_wcstombs (char *dst, size_t len, const wchar_t * src, size_t nwc)
500500
{
501501
return sys_wcstombs (dst, len, src, nwc, false);
502502
}
@@ -534,13 +534,13 @@ sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc,
534534
}
535535

536536
size_t __reg3
537-
sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc)
537+
sys_wcstombs_alloc_path (char **dst_p, int type, const wchar_t *src, size_t nwc)
538538
{
539539
return sys_wcstombs_alloc (dst_p, type, src, nwc, true);
540540
}
541541

542542
size_t __reg3
543-
sys_wcstombs_alloc_no_path (char **dst_p, int type, const wchar_t *src,
543+
sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src,
544544
size_t nwc)
545545
{
546546
return sys_wcstombs_alloc (dst_p, type, src, nwc, false);

0 commit comments

Comments
 (0)