Skip to content

Commit 8626feb

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 <johannes.schindelin@gmx.de>
2 parents 12de314 + bfd65a4 commit 8626feb

File tree

14 files changed

+62
-56
lines changed

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
@@ -834,7 +834,7 @@ environ_init (char **envp, int envc)
834834
eventually want to use them). */
835835
for (i = 0, w = rawenv; *w != L'\0'; w = wcschr (w, L'\0') + 1, i++)
836836
{
837-
sys_wcstombs_alloc_no_path (&newp, HEAP_NOTHEAP, w);
837+
sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w);
838838
if (i >= envc)
839839
envp = (char **) realloc (envp, (4 + (envc += 100)) * sizeof (char *));
840840
envp[i] = newp;
@@ -913,15 +913,15 @@ getwinenveq (const char *name, size_t namelen, int x)
913913
int totlen = GetEnvironmentVariableW (name0, valbuf, 32768);
914914
if (totlen > 0)
915915
{
916-
totlen = sys_wcstombs_no_path (NULL, 0, valbuf) + 1;
916+
totlen = sys_wcstombs (NULL, 0, valbuf) + 1;
917917
if (x == HEAP_1_STR)
918918
totlen += namelen;
919919
else
920920
namelen = 0;
921921
char *p = (char *) cmalloc_abort ((cygheap_types) x, totlen);
922922
if (namelen)
923923
strcpy (p, name);
924-
sys_wcstombs_no_path (p + namelen, totlen, valbuf);
924+
sys_wcstombs (p + namelen, totlen, valbuf);
925925
debug_printf ("using value from GetEnvironmentVariable for '%W'", name0);
926926
return p;
927927
}
@@ -1074,7 +1074,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
10741074
for (winnum = 0, var = cwinenv;
10751075
*var;
10761076
++winnum, var = wcschr (var, L'\0') + 1)
1077-
sys_wcstombs_alloc_no_path (&winenv[winnum], HEAP_NOTHEAP, var);
1077+
sys_wcstombs_alloc (&winenv[winnum], HEAP_NOTHEAP, var);
10781078
}
10791079
DestroyEnvironmentBlock (cwinenv);
10801080
/* 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
@@ -563,10 +563,10 @@ static off_t
563563
format_process_winexename (void *data, char *&destbuf)
564564
{
565565
_pinfo *p = (_pinfo *) data;
566-
size_t len = sys_wcstombs (NULL, 0, p->progname);
566+
size_t len = sys_wcstombs_path (NULL, 0, p->progname);
567567
destbuf = (char *) crealloc_abort (destbuf, len + 1);
568568
/* With trailing \0 for backward compat reasons. */
569-
sys_wcstombs (destbuf, len + 1, p->progname);
569+
sys_wcstombs_path (destbuf, len + 1, p->progname);
570570
return len;
571571
}
572572

@@ -1006,7 +1006,7 @@ format_process_maps (void *data, char *&destbuf)
10061006
drive_maps.fixup_if_match (msi->SectionFileName.Buffer);
10071007
if (mount_table->conv_to_posix_path (dosname,
10081008
posix_modname, 0))
1009-
sys_wcstombs (posix_modname, NT_MAX_PATH, dosname);
1009+
sys_wcstombs_path (posix_modname, NT_MAX_PATH, dosname);
10101010
stat64 (posix_modname, &st);
10111011
}
10121012
else if (!threads.fill_if_match (cur.abase, mb.Type,
@@ -1052,7 +1052,7 @@ format_process_stat (void *data, char *&destbuf)
10521052
else
10531053
{
10541054
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
1055-
sys_wcstombs (cmd, NAME_MAX + 1,
1055+
sys_wcstombs_path (cmd, NAME_MAX + 1,
10561056
last_slash ? last_slash + 1 : p->progname);
10571057
int len = strlen (cmd);
10581058
if (len > 4)
@@ -1170,7 +1170,8 @@ format_process_status (void *data, char *&destbuf)
11701170
vmtext = 0UL, vmshare = 0UL;
11711171

11721172
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
1173-
sys_wcstombs (cmd, NAME_MAX + 1, last_slash ? last_slash + 1 : p->progname);
1173+
sys_wcstombs_path (cmd, NAME_MAX + 1,
1174+
last_slash ? last_slash + 1 : p->progname);
11741175
int len = strlen (cmd);
11751176
if (len > 4)
11761177
{

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
@@ -435,7 +435,7 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
435435
{
436436
/* The filesystem name is only used in fillout_mntent and only if
437437
the filesystem isn't one of the well-known filesystems anyway. */
438-
sys_wcstombs (fsn, sizeof fsn, ffai_buf.ffai.FileSystemName,
438+
sys_wcstombs_path (fsn, sizeof fsn, ffai_buf.ffai.FileSystemName,
439439
ffai_buf.ffai.FileSystemNameLength / sizeof (WCHAR));
440440
strlwr (fsn);
441441
}
@@ -462,7 +462,7 @@ mount_info::create_root_entry (const PWCHAR root)
462462
/* Create a default root dir derived from the location of the Cygwin DLL.
463463
The entry is immutable, unless the "override" option is given in /etc/fstab. */
464464
char native_root[PATH_MAX];
465-
sys_wcstombs (native_root, PATH_MAX, root);
465+
sys_wcstombs_path (native_root, PATH_MAX, root);
466466
assert (*native_root != '\0');
467467
if (add_item (native_root, "/",
468468
MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_IMMUTABLE | MOUNT_AUTOMATIC | MOUNT_NOACL)
@@ -858,7 +858,7 @@ mount_info::conv_to_posix_path (PWCHAR src_path, char *posix_path,
858858
}
859859
tmp_pathbuf tp;
860860
char *buf = tp.c_get ();
861-
sys_wcstombs (buf, NT_MAX_PATH, src_path);
861+
sys_wcstombs_path (buf, NT_MAX_PATH, src_path);
862862
int ret = conv_to_posix_path (buf, posix_path, ccp_flags);
863863
if (changed)
864864
src_path[0] = L'C';
@@ -1204,7 +1204,7 @@ mount_info::from_fstab_line (char *line, bool user)
12041204
{
12051205
tmp_pathbuf tp;
12061206
char *mb_tmp = tp.c_get ();
1207-
sys_wcstombs (mb_tmp, PATH_MAX, tmp);
1207+
sys_wcstombs_path (mb_tmp, PATH_MAX, tmp);
12081208

12091209
mount_flags |= MOUNT_USER_TEMP;
12101210
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
}

0 commit comments

Comments
 (0)