From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 63EFC3857C42; Thu, 1 Feb 2024 11:39:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63EFC3857C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706787585; bh=4NtcS7P5ySM9ItWMYjj2WI6eUo0VK9Dua9dvoIMDFj8=; h=From:To:Subject:Date:From; b=OPWyCXiG+Q7YvCX3gI4Xzzao3QY92rS/dU31R2EzlzlM9FyW5vI86oCxrzhc6H5ck nqBKyFk/wvwFIXAlcXX74GOKDA3cRU1B625AcTIICPYC8AbUTuOerd01fIJTT7ByVN kOX4RkVsfumsqlYLIMjNif/R3pyTIaRk8owCQm+g= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: b1d64ac265f01f2efcff495b963982ca741269d9 X-Git-Newrev: 732afede935832beab181ae421c1366df2ae6af5 Message-Id: <20240201113945.63EFC3857C42@sourceware.org> Date: Thu, 1 Feb 2024 11:39:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D732afede935= 832beab181ae421c1366df2ae6af5 commit 732afede935832beab181ae421c1366df2ae6af5 Author: Corinna Vinschen AuthorDate: Tue Jan 30 20:46:09 2024 +0100 Commit: Corinna Vinschen CommitDate: Wed Jan 31 20:11:58 2024 +0100 Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC =20 Make sure to =20 - append a trailing \0 as with Windows multistrings, so the end of the string can be recognized by the caller, and =20 - allocate cmdline on the user heap so the caller can free the multistring after usage. =20 Fixes: 831d6fa520ed4 ("* external.cc (cygwin_internal): Implement CW_CM= DLINE.") Signed-off-by: Corinna Vinschen 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 =3D 0; } break; - case CW_CMDLINE: + + case CW_CMDLINE_ALLOC: { size_t n; + char *cmdline_cheap; + char *cmdline; + pid_t pid =3D va_arg (arg, pid_t); pinfo p (pid); - res =3D (uintptr_t) (p ? p->cmdline (n) : NULL); + cmdline_cheap =3D (p ? p->cmdline (n) : NULL); + if (cmdline_cheap) + { + cmdline =3D (char *) malloc (n + 1); + if (cmdline) + { + memcpy (cmdline, cmdline_cheap, n); + cmdline[n] =3D '\0'; + } + cfree (cmdline_cheap); + } + res =3D (uintptr_t) cmdline; } break; + case CW_CHECK_NTSEC: { char *filename =3D va_arg (arg, char *); res =3D check_ntsec (filename); } break; + case CW_GET_ERRNO_FROM_WINERROR: { int error =3D va_arg (arg, int); @@ -365,6 +382,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D 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 =3D wincap.allocation_granularity (); } break; + case CW_GET_UID_FROM_SID: { cygpsid psid =3D va_arg (arg, PSID); res =3D psid.get_uid (NULL); } break; + case CW_GET_GID_FROM_SID: { cygpsid psid =3D va_arg (arg, PSID); res =3D psid.get_gid (NULL); } break; + case CW_GET_BINMODE: { const char *path =3D va_arg (arg, const char *); @@ -413,6 +435,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D p.binmode (); } break; + case CW_HOOK: { const char *name =3D va_arg (arg, const char *); @@ -421,32 +444,39 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D (uintptr_t) hook_or_detect_cygwin (name, hookfn, subsys); } break; + case CW_ARGV: { child_info_spawn *ci =3D (child_info_spawn *) get_cygwin_startup_info (= ); res =3D (uintptr_t) (ci ? ci->moreinfo->argv : NULL); } break; + case CW_ENVP: { child_info_spawn *ci =3D (child_info_spawn *) get_cygwin_startup_info (= ); res =3D (uintptr_t) (ci ? ci->moreinfo->envp : NULL); } break; + case CW_DEBUG_SELF: error_start_init (va_arg (arg, const char *)); res =3D try_to_debug (); break; + case CW_SYNC_WINENV: create_winenv (NULL); res =3D 0; break; + case CW_CYGTLS_PADSIZE: res =3D __CYGTLS_PADSIZE__; break; + case CW_SET_DOS_FILE_WARNING: res =3D 0; break; + case CW_SET_PRIV_KEY: { const char *passwd =3D va_arg (arg, const char *); @@ -454,6 +484,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D setlsapwd (passwd, username); } break; + case CW_SETERRNO: { const char *file =3D va_arg (arg, const char *); @@ -462,6 +493,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D 0; } break; + case CW_EXIT_PROCESS: { UINT status =3D va_arg (arg, UINT); @@ -476,6 +508,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D 0; } break; + case CW_GET_INSTKEY: { PWCHAR dest =3D va_arg (arg, PWCHAR); @@ -483,6 +516,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D 0; } break; + case CW_INT_SETLOCALE: { extern void internal_setlocale (); @@ -490,6 +524,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) res =3D 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 =3D 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