VirtualBox

Changeset 100317 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Jun 28, 2023 10:34:21 AM (23 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158032
Message:

Additions: Get rid of MAX_MNTOPT_STR and replace with RTSystemGetPageSize() in the shared folders mounting tools, bugref:10476

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp

    r99828 r100317  
    5555#include <iprt/sort.h>
    5656#include <iprt/string.h>
     57#include <iprt/system.h>
    5758#include <VBox/err.h>
    5859#include <VBox/VBoxGuestLib.h>
     
    6869# include <os2emx.h>
    6970#else
     71# include <alloca.h>
    7072# include <errno.h>
    7173# include <grp.h>
     
    387389    if (RT_SUCCESS(rc))
    388390    {
     391        uint32_t cbOpts = RTSystemGetPageSize();
     392        char *pszOpts = (char *)alloca(cbOpts);
     393        RT_BZERO(pszOpts, cbOpts);
     394
    389395# ifdef RT_OS_SOLARIS
    390396        int const fFlags = MS_OPTIONSTR;
    391         char szOptBuf[MAX_MNTOPT_STR] = { '\0', };
    392         RTStrPrintf(szOptBuf, sizeof(szOptBuf), "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", grp_vboxsf->gr_gid);
     397        RTStrPrintf(pszOptBuf, sizeof(szOptBuf), "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", grp_vboxsf->gr_gid);
    393398        int r = mount(pszShareName,
    394399                      pszMountPoint,
     
    397402                      NULL,                     /* char *dataptr */
    398403                      0,                        /* int datalen */
    399                       szOptBuf,
    400                       sizeof(szOptBuf));
     404                      pszOpts,
     405                      cbOpts);
    401406        if (r == 0)
    402407            VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", pszShareName, pszMountPoint);
     
    410415
    411416        unsigned long const fFlags = MS_NODEV;
    412         char szOpts[MAX_MNTOPT_STR] = { '\0' };
    413         ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts), "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000",
     417        ssize_t cchOpts = RTStrPrintf2(pszOpts, cbOpts, "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000",
    414418                                       grp_vboxsf->gr_gid);
    415419        if (cchOpts > 0 && RTStrVersionCompare(uts.release, "2.6.0") < 0)
    416             cchOpts = RTStrPrintf2(&szOpts[cchOpts], sizeof(szOpts) - cchOpts, ",sf_name=%s", pszShareName);
     420            cchOpts = RTStrPrintf2(&pszOpts[cchOpts], cbOpts - cchOpts, ",sf_name=%s", pszShareName);
    417421        if (cchOpts <= 0)
    418422        {
    419             VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd (share %s)\n", cchOpts, pszShareName);
     423            VGSvcError("vbsvcAutomounterMountIt: pszOpts overflow! %zd (share %s)\n", cchOpts, pszShareName);
    420424            return VERR_BUFFER_OVERFLOW;
    421425        }
     
    425429                      "vboxsf",
    426430                      fFlags,
    427                       szOpts);
     431                      pszOpts);
    428432        if (r == 0)
    429433        {
    430434            VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", pszShareName, pszMountPoint);
    431435
    432             r = vbsfmount_complete(pszShareName, pszMountPoint, fFlags, szOpts);
     436            r = vbsfmount_complete(pszShareName, pszMountPoint, fFlags, pszOpts);
    433437            switch (r)
    434438            {
     
    14651469    }
    14661470
     1471    /*
     1472     * Allocate options string buffer which is limited to a page on most systems.
     1473     */
     1474    uint32_t cbOpts = RTSystemGetPageSize();
     1475    char *pszOpts = (char *)alloca(cbOpts);
     1476
    14671477#  if defined(RT_OS_LINUX)
    14681478    /*
     
    14741484    /* Built mount option string.  Need st_name for pre 2.6.0 kernels. */
    14751485    unsigned long const fFlags = MS_NODEV;
    1476     char szOpts[MAX_MNTOPT_STR] = { '\0' };
    1477     ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts),
     1486    ssize_t cchOpts = RTStrPrintf2(pszOpts, cbOpts,
    14781487                                   "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000,tag=%s", gidMount, g_szTag);
    14791488    if (RTStrVersionCompare(uts.release, "2.6.0") < 0 && cchOpts > 0)
    1480         cchOpts += RTStrPrintf2(&szOpts[cchOpts], sizeof(szOpts) - cchOpts, ",sf_name=%s", pEntry->pszName);
     1489        cchOpts += RTStrPrintf2(&pszOpts[cchOpts], cbOpts - cchOpts, ",sf_name=%s", pEntry->pszName);
    14811490    if (cchOpts <= 0)
    14821491    {
    1483         VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd\n", cchOpts);
     1492        VGSvcError("vbsvcAutomounterMountIt: pszOpts overflow! %zd\n", cchOpts);
    14841493        return VERR_BUFFER_OVERFLOW;
    14851494    }
     
    14881497       which lagged a lot behind when it first appeared in 5.6. */
    14891498    errno = 0;
    1490     rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, szOpts);
     1499    rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, pszOpts);
    14911500    if (rc != 0 && errno == EINVAL && RTStrVersionCompare(uts.release, "5.6.0") >= 0)
    14921501    {
    14931502        VGSvcVerbose(2, "vbsvcAutomounterMountIt: mount returned EINVAL, retrying without the tag.\n");
    1494         *strstr(szOpts, ",tag=") = '\0';
     1503        *strstr(pszOpts, ",tag=") = '\0';
    14951504        errno = 0;
    1496         rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, szOpts);
     1505        rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, pszOpts);
    14971506        if (rc == 0)
    14981507            VGSvcVerbose(0, "vbsvcAutomounterMountIt: Running outdated vboxsf module without support for the 'tag' option?\n");
     
    15041513
    15051514        errno = 0;
    1506         rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, szOpts);
     1515        rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, pszOpts);
    15071516        if (rc != 0) /* Ignorable. /etc/mtab is probably a link to /proc/mounts. */
    15081517            VGSvcVerbose(1, "vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n",
     
    15291538     *       with EOVERFLOW in vfs_buildoptionstr() during domount() otherwise.
    15301539     */
    1531     char szOpts[MAX_MNTOPT_STR] = { '\0', };
    1532     ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts),
     1540    ssize_t cchOpts = RTStrPrintf2(pszOpts, cbOpts,
    15331541                                   "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000,tag=%s", gidMount, g_szTag);
    15341542    if (cchOpts <= 0)
    15351543    {
    1536         VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd\n", cchOpts);
     1544        VGSvcError("vbsvcAutomounterMountIt: pszOpts overflow! %zd\n", cchOpts);
    15371545        return VERR_BUFFER_OVERFLOW;
    15381546    }
    15391547
    15401548    rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, MS_OPTIONSTR, "vboxfs",
    1541                NULL /*dataptr*/, 0 /* datalen */, szOpts, MAX_MNTOPT_STR);
     1549               NULL /*dataptr*/, 0 /* datalen */, pszOpts, MAX_MNTOPT_STR);
    15421550    if (rc == 0)
    15431551    {
     
    15481556
    15491557    rc = errno;
    1550     VGSvcError("vbsvcAutomounterMountIt: mount failed for '%s' on '%s' (szOpts=%s): %s (%d)\n",
    1551                pEntry->pszName, pEntry->pszActualMountPoint, szOpts, strerror(rc), rc);
     1558    VGSvcError("vbsvcAutomounterMountIt: mount failed for '%s' on '%s' (pszOpts=%s): %s (%d)\n",
     1559               pEntry->pszName, pEntry->pszActualMountPoint, pszOpts, strerror(rc), rc);
    15521560    return VERR_OPEN_FAILED;
    15531561
Note: See TracChangeset for help on using the changeset viewer.

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