public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC
@ 2024-02-01 11:39 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2024-02-01 11:39 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=732afede935832beab181ae421c1366df2ae6af5
commit 732afede935832beab181ae421c1366df2ae6af5
Author: Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Jan 30 20:46:09 2024 +0100
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Jan 31 20:11:58 2024 +0100
Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC
Make sure to
- append a trailing \0 as with Windows multistrings, so the end of
the string can be recognized by the caller, and
- allocate cmdline on the user heap so the caller can free the
multistring after usage.
Fixes: 831d6fa520ed4 ("* external.cc (cygwin_internal): Implement CW_CMDLINE.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/external.cc | 41 ++++++++++++++++++++++++++++++++++++--
winsup/cygwin/include/sys/cygwin.h | 4 ++--
2 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc
index 97e45287411c..555422b83ece 100644
--- a/winsup/cygwin/external.cc
+++ b/winsup/cygwin/external.cc
@@ -344,20 +344,37 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = 0;
}
break;
- case CW_CMDLINE:
+
+ case CW_CMDLINE_ALLOC:
{
size_t n;
+ char *cmdline_cheap;
+ char *cmdline;
+
pid_t pid = va_arg (arg, pid_t);
pinfo p (pid);
- res = (uintptr_t) (p ? p->cmdline (n) : NULL);
+ cmdline_cheap = (p ? p->cmdline (n) : NULL);
+ if (cmdline_cheap)
+ {
+ cmdline = (char *) malloc (n + 1);
+ if (cmdline)
+ {
+ memcpy (cmdline, cmdline_cheap, n);
+ cmdline[n] = '\0';
+ }
+ cfree (cmdline_cheap);
+ }
+ res = (uintptr_t) cmdline;
}
break;
+
case CW_CHECK_NTSEC:
{
char *filename = va_arg (arg, char *);
res = check_ntsec (filename);
}
break;
+
case CW_GET_ERRNO_FROM_WINERROR:
{
int error = va_arg (arg, int);
@@ -365,6 +382,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = geterrno_from_win_error (error, deferrno);
}
break;
+
case CW_GET_POSIX_SECURITY_ATTRIBUTE:
{
path_conv dummy;
@@ -383,23 +401,27 @@ cygwin_internal (cygwin_getinfo_types t, ...)
}
}
break;
+
case CW_GET_SHMLBA:
{
res = wincap.allocation_granularity ();
}
break;
+
case CW_GET_UID_FROM_SID:
{
cygpsid psid = va_arg (arg, PSID);
res = psid.get_uid (NULL);
}
break;
+
case CW_GET_GID_FROM_SID:
{
cygpsid psid = va_arg (arg, PSID);
res = psid.get_gid (NULL);
}
break;
+
case CW_GET_BINMODE:
{
const char *path = va_arg (arg, const char *);
@@ -413,6 +435,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = p.binmode ();
}
break;
+
case CW_HOOK:
{
const char *name = va_arg (arg, const char *);
@@ -421,32 +444,39 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = (uintptr_t) hook_or_detect_cygwin (name, hookfn, subsys);
}
break;
+
case CW_ARGV:
{
child_info_spawn *ci = (child_info_spawn *) get_cygwin_startup_info ();
res = (uintptr_t) (ci ? ci->moreinfo->argv : NULL);
}
break;
+
case CW_ENVP:
{
child_info_spawn *ci = (child_info_spawn *) get_cygwin_startup_info ();
res = (uintptr_t) (ci ? ci->moreinfo->envp : NULL);
}
break;
+
case CW_DEBUG_SELF:
error_start_init (va_arg (arg, const char *));
res = try_to_debug ();
break;
+
case CW_SYNC_WINENV:
create_winenv (NULL);
res = 0;
break;
+
case CW_CYGTLS_PADSIZE:
res = __CYGTLS_PADSIZE__;
break;
+
case CW_SET_DOS_FILE_WARNING:
res = 0;
break;
+
case CW_SET_PRIV_KEY:
{
const char *passwd = va_arg (arg, const char *);
@@ -454,6 +484,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = setlsapwd (passwd, username);
}
break;
+
case CW_SETERRNO:
{
const char *file = va_arg (arg, const char *);
@@ -462,6 +493,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = 0;
}
break;
+
case CW_EXIT_PROCESS:
{
UINT status = va_arg (arg, UINT);
@@ -476,6 +508,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = 0;
}
break;
+
case CW_GET_INSTKEY:
{
PWCHAR dest = va_arg (arg, PWCHAR);
@@ -483,6 +516,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = 0;
}
break;
+
case CW_INT_SETLOCALE:
{
extern void internal_setlocale ();
@@ -490,6 +524,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
res = 0;
}
break;
+
case CW_CVT_MNT_OPTS:
{
extern bool fstab_read_flags (char **, unsigned &, bool);
@@ -509,6 +544,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
}
}
break;
+
case CW_LST_MNT_OPTS:
{
extern char *fstab_list_flags ();
@@ -523,6 +559,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
}
}
break;
+
case CW_STRERROR:
{
int err = va_arg (arg, int);
diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h
index 2c5997b5e208..f5c90fe96b81 100644
--- a/winsup/cygwin/include/sys/cygwin.h
+++ b/winsup/cygwin/include/sys/cygwin.h
@@ -95,7 +95,7 @@ typedef enum
CW_STRACE_ACTIVE,
CW_CYGWIN_PID_TO_WINPID,
CW_EXTRACT_DOMAIN_AND_USER,
- CW_CMDLINE,
+ CW_CMDLINE_ALLOC,
CW_CHECK_NTSEC,
CW_GET_ERRNO_FROM_WINERROR,
CW_GET_POSIX_SECURITY_ATTRIBUTE,
@@ -159,7 +159,7 @@ typedef enum
#define CW_STRACE_ACTIVE CW_STRACE_ACTIVE
#define CW_CYGWIN_PID_TO_WINPID CW_CYGWIN_PID_TO_WINPID
#define CW_EXTRACT_DOMAIN_AND_USER CW_EXTRACT_DOMAIN_AND_USER
-#define CW_CMDLINE CW_CMDLINE
+#define CW_CMDLINE_ALLOC CW_CMDLINE_ALLOC
#define CW_CHECK_NTSEC CW_CHECK_NTSEC
#define CW_GET_ERRNO_FROM_WINERROR CW_GET_ERRNO_FROM_WINERROR
#define CW_GET_POSIX_SECURITY_ATTRIBUTE CW_GET_POSIX_SECURITY_ATTRIBUTE
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-01 11:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01 11:39 [newlib-cygwin/main] Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).