VirtualBox

Changeset 85425 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 23, 2020 10:31:35 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139468
Message:

FE/Qt: bugref:9722: VirtualBox Manager: On unix-like platforms we have to parse console application arguments using shell rules before passing them to QProcess, else Qt will break them up to fubar condition; This implementation handles quoting but doesn't yet handle escape characters.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r85412 r85425  
    2626#include <QStatusBar>
    2727#include <QTextEdit>
     28#ifndef VBOX_WS_WIN
     29# include <QRegExp>
     30#endif
    2831
    2932/* GUI includes: */
     
    12371240void UIVirtualBoxManager::sltExecuteExternalApplication()
    12381241{
    1239     /* Acquire passed path and argument: */
     1242    /* Acquire passed path and argument strings: */
    12401243    QAction *pAction = qobject_cast<QAction*>(sender());
    12411244    AssertMsgReturnVoid(pAction, ("This slot should be called by action only!\n"));
    12421245    const QString strPath = pAction->property("path").toString();
    1243     QStringList arguments = pAction->property("arguments").toString().split(' ');
     1246    const QString strArguments = pAction->property("arguments").toString();
    12441247
    12451248    /* Get current-item: */
     
    12491252    AssertPtrReturnVoid(pCloudItem);
    12501253
    1251     /* Add serial command to arguments: */
     1254    /* Get cloud machine to acquire serial command: */
    12521255    const CCloudMachine comMachine = pCloudItem->machine();
     1256
    12531257#ifdef VBOX_WS_WIN
     1258    /* Gather arguments: */
     1259    QStringList arguments;
     1260    arguments << strArguments;
    12541261    arguments << comMachine.GetSerialConsoleCommandWindows();
    1255 #else
     1262
     1263    /* Execute console application finally: */
     1264    QProcess::startDetached(QString("%1 %2").arg(strPath, arguments.join(' ')));
     1265#else /* !VBOX_WS_WIN */
     1266    /* Gather arguments: */
     1267    QStringList arguments;
     1268    arguments << parseShellArguments(strArguments);
    12561269    arguments << comMachine.GetSerialConsoleCommand();
    1257 #endif
    12581270
    12591271    /* Execute console application finally: */
    12601272    QProcess::startDetached(strPath, arguments);
     1273#endif /* !VBOX_WS_WIN */
    12611274}
    12621275
     
    24402453}
    24412454
     2455#ifndef VBOX_WS_WIN
     2456QStringList UIVirtualBoxManager::parseShellArguments(const QString &strArguments)
     2457{
     2458    //printf("start processing arguments\n");
     2459
     2460    /* Parse argument string: */
     2461    QStringList arguments;
     2462    QRegExp re("(\"[^\"]+\")|('[^']+')|([^\\s\"']+)");
     2463    int iPosition = 0;
     2464    int iIndex = re.indexIn(strArguments, iPosition);
     2465    while (iIndex != -1)
     2466    {
     2467        /* Get what's the sequence we have: */
     2468        const QString strCap0 = re.cap(0);
     2469        /* Get what's the double-quoted sequence we have: */
     2470        const QString strCap1 = re.cap(1);
     2471        /* Get what's the single-quoted sequence we have: */
     2472        const QString strCap2 = re.cap(2);
     2473        /* Get what's the unquoted sequence we have: */
     2474        const QString strCap3 = re.cap(3);
     2475
     2476        /* If new sequence starts where previous ended
     2477         * we are appending new value to previous one, otherwise
     2478         * we are appending new value to argument list itself.. */
     2479
     2480        /* Do we have double-quoted sequence? */
     2481        if (!strCap1.isEmpty())
     2482        {
     2483            //printf(" [D] double-quoted sequence starting at: %d\n", iIndex);
     2484            /* Unquote the value and add it to the list: */
     2485            const QString strValue = strCap1.mid(1, strCap1.size() - 2);
     2486            if (!arguments.isEmpty() && iIndex == iPosition)
     2487                arguments.last() += strValue;
     2488            else
     2489                arguments << strValue;
     2490        }
     2491        /* Do we have single-quoted sequence? */
     2492        else if (!strCap2.isEmpty())
     2493        {
     2494            //printf(" [S] single-quoted sequence starting at: %d\n", iIndex);
     2495            /* Unquote the value and add it to the list: */
     2496            const QString strValue = strCap2.mid(1, strCap2.size() - 2);
     2497            if (!arguments.isEmpty() && iIndex == iPosition)
     2498                arguments.last() += strValue;
     2499            else
     2500                arguments << strValue;
     2501        }
     2502        /* Do we have unquoted sequence? */
     2503        else if (!strCap3.isEmpty())
     2504        {
     2505            //printf(" [U] unquoted sequence starting at: %d\n", iIndex);
     2506            /* Value wasn't unquoted, add it to the list: */
     2507            if (!arguments.isEmpty() && iIndex == iPosition)
     2508                arguments.last() += strCap3;
     2509            else
     2510                arguments << strCap3;
     2511        }
     2512
     2513        /* Advance position: */
     2514        iPosition = iIndex + strCap0.size();
     2515        /* Search for a next sequence: */
     2516        iIndex = re.indexIn(strArguments, iPosition);
     2517    }
     2518
     2519    //printf("arguments processed:\n");
     2520    //foreach (const QString &strArgument, arguments)
     2521    //    printf(" %s\n", strArgument.toUtf8().constData());
     2522
     2523    /* Return parsed arguments: */
     2524    return arguments;
     2525}
     2526#endif /* !VBOX_WS_WIN */
     2527
    24422528void UIVirtualBoxManager::updateMenuGroup(QMenu *pMenu)
    24432529{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r85396 r85425  
    360360    /** @} */
    361361
    362     /** @name VM add stuff.
     362    /** @name Various VM helpers.
    363363      * @{ */
    364364        /** Opens add machine dialog specifying initial name with @a strFileName. */
    365365        void openAddMachineDialog(const QString &strFileName = QString());
    366        /** Creates an uattended installer and uses that to install guest os to newly created vm. */
     366
     367        /** Creates an unattended installer and uses it to install guest os to newly created vm. */
    367368        void startUnattendedInstall(CUnattended &comUnattendedInstaller, const UIUnattendedInstallData &unattendedData);
    368     /** @} */
    369 
    370     /** @name VM launching stuff.
    371       * @{ */
     369
    372370        /** Launches or shows virtual machines represented by passed @a items in corresponding @a enmLaunchMode (for launch). */
    373371        void performStartOrShowVirtualMachines(const QList<UIVirtualMachineItem*> &items, UICommon::LaunchMode enmLaunchMode);
     372
     373#ifndef VBOX_WS_WIN
     374        /** Parses serialized @a strArguments string according to shell rules. */
     375        QStringList parseShellArguments(const QString &strArguments);
     376#endif
    374377    /** @} */
    375378
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