VirtualBox

Ignore:
Timestamp:
Nov 29, 2021 1:47:56 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
148510
Message:

IPRT,RTProcCreatEx/posix: Do *not* use achBuf for temporary stuff, just use a dedicated buffer of RTPATH_MAX size for that. Corrected incorrect rtProcPosixProfileEnvRunAndHarvest docs (pszAsUser won't be NULL). bugref:10153

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp

    r92617 r92618  
    563563        && (!(fFlags & RTPROC_FLAGS_ENV_CHANGE_RECORD) || RTEnvExistEx(hEnv, "TMPDIR")) )
    564564    {
    565         char szValue[_4K];
     565        char szValue[RTPATH_MAX];
    566566        size_t cbNeeded = confstr(_CS_DARWIN_USER_TEMP_DIR, szValue, sizeof(szValue));
    567567        if (cbNeeded > 0 && cbNeeded < sizeof(szValue))
     
    690690 *          can guess to accurately up front, so we don't do any guessing and
    691691 *          hope everyone is sensible and use UTF-8.
     692 *
    692693 * @param   hEnvToUse       The basic environment to extend with what we manage
    693694 *                          to parse here.
     
    810811 * @returns IPRT status code.  Not all error statuses will be returned and the
    811812 *          caller should just continue with whatever is in hEnvToUse.
     813 *
    812814 * @param   hEnvToUse   On input this is the basic user environment, on success
    813815 *                      in is fleshed out with stuff from the login shell dump.
    814  * @param   pszAsUser   The user name for the profile.  NULL if the current
    815  *                      user.
    816  * @param   uid         The UID corrsponding to @a pszAsUser, ~0 if NULL.
    817  * @param   gid         The GID corrsponding to @a pszAsUser, ~0 if NULL.
     816 * @param   pszAsUser   The user name for the profile.
     817 * @param   uid         The UID corrsponding to @a pszAsUser, ~0 if current user.
     818 * @param   gid         The GID corrsponding to @a pszAsUser, ~0 if current user.
    818819 * @param   pszShell    The login shell.  This is a writable string to avoid
    819820 *                      needing to make a copy of it when examining the path
     
    10471048static int rtProcPosixCreateProfileEnv(PRTENV phEnvToUse, const char *pszAsUser, uid_t uid, gid_t gid, uint32_t fFlags)
    10481049{
     1050    /*
     1051     * Get the passwd entry for the user.
     1052     */
    10491053    struct passwd   Pwd;
    10501054    struct passwd  *pPwd = NULL;
     
    10581062    if (rc == 0 && pPwd)
    10591063    {
     1064        /*
     1065         * Convert stuff to UTF-8 since the environment is UTF-8.
     1066         */
    10601067        char *pszDir;
    10611068        rc = RTStrCurrentCPToUtf8(&pszDir, pPwd->pw_dir);
     
    10781085                if (RT_SUCCESS(rc))
    10791086                {
     1087                    /*
     1088                     * Create and populate the environment.
     1089                     */
    10801090                    rc = RTEnvCreate(phEnvToUse);
    10811091                    if (RT_SUCCESS(rc))
    10821092                    {
    10831093                        RTENV hEnvToUse = *phEnvToUse;
    1084 
    10851094                        rc = RTEnvSetEx(hEnvToUse, "HOME", pszDir);
    10861095                        if (RT_SUCCESS(rc))
     
    10901099                        if (RT_SUCCESS(rc))
    10911100                            rc = RTEnvSetEx(hEnvToUse, "LOGNAME", pszAsUser);
    1092 
    10931101                        if (RT_SUCCESS(rc))
    10941102                            rc = RTEnvSetEx(hEnvToUse, "PATH", pPwd->pw_uid == 0 ? _PATH_STDPATH : _PATH_DEFPATH);
    1095 
     1103                        char szTmpPath[RTPATH_MAX];
    10961104                        if (RT_SUCCESS(rc))
    10971105                        {
    1098                             RTStrPrintf(achBuf, sizeof(achBuf), "%s/%s", _PATH_MAILDIR, pszAsUser);
    1099                             rc = RTEnvSetEx(hEnvToUse, "MAIL", achBuf);
     1106                            RTStrPrintf(szTmpPath, sizeof(szTmpPath), "%s/%s", _PATH_MAILDIR, pszAsUser);
     1107                            rc = RTEnvSetEx(hEnvToUse, "MAIL", szTmpPath);
    11001108                        }
    1101 
    11021109#ifdef RT_OS_DARWIN
     1110                        /** @todo r=bird: we should do this for pszAsUserFree == NULL too! */
    11031111                        if (RT_SUCCESS(rc) && !pszAsUserFree)
    11041112                        {
    1105                             size_t cbNeeded = confstr(_CS_DARWIN_USER_TEMP_DIR, achBuf, sizeof(achBuf));
    1106                             if (cbNeeded > 0 && cbNeeded < sizeof(achBuf))
     1113                            /* We put the "wrong" TMPDIR here now and then let
     1114                               rtProcPosixAdjustProfileEnvFromChild fix it later on. See
     1115                               https://opensource.apple.com/source/Libc/Libc-997.1.1/darwin/_dirhelper.c
     1116                               for the implemntation of this query. */
     1117                            size_t cbNeeded = confstr(_CS_DARWIN_USER_TEMP_DIR, szTmpPath, sizeof(szTmpPath));
     1118                            if (cbNeeded > 0 && cbNeeded < sizeof(szTmpPath))
    11071119                            {
    11081120                                char *pszTmp;
    1109                                 rc = RTStrCurrentCPToUtf8(&pszTmp, achBuf);
     1121                                rc = RTStrCurrentCPToUtf8(&pszTmp, szTmpPath);
    11101122                                if (RT_SUCCESS(rc))
    11111123                                {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette