VirtualBox

Changeset 89947 in vbox


Ignore:
Timestamp:
Jun 29, 2021 10:42:28 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145405
Message:

X11: Host Services: Shared Clipboard: improve error code path handling, bugref:10038.

This commit improves error code path handling for X11 part of host Shared Clipboard
service. In particular, it adjusts initialization calls to match to its de-init counterpart.
It also adds more resources release on error path. In addition, this commit limits number of
simmultaneous HGCM connections to ShCl host service in order to prevent potential host flooding.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard-x11.h

    r87566 r89947  
    3838# include <VBox/GuestHost/SharedClipboard-transfers.h>
    3939#endif
     40
     41/**
     42 * The maximum number of simultaneous connections to shared clipboard service.
     43 * This constant limits amount of GUEST -> HOST connections to shared clipboard host service
     44 * for X11 host only. Once amount of connections reaches this number, all the
     45 * further attempts to CONNECT will be dropped on an early stage. Possibility to connect
     46 * is available again after one of existing connections is closed by DISCONNECT call.
     47 */
     48#define VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX   (20)
    4049
    4150/** Enables the Xt busy / update handling. */
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp

    r87566 r89947  
    279279
    280280/**
    281  * The number of simultaneous instances we support.  For all normal purposes
    282  * we should never need more than one.  For the testcase it is convenient to
    283  * have a second instance that the first can interact with in order to have
    284  * a more controlled environment.
    285  */
    286 enum { CLIP_MAX_CONTEXTS = 20 };
    287 
    288 /**
    289281 * Array of structures for mapping Xt widgets to context pointers.  We
    290282 * need this because the widget clipboard callbacks do not pass user data.
     
    296288    /** Pointer to X11 context associated with the widget. */
    297289    PSHCLX11CTX pCtx;
    298 } g_aContexts[CLIP_MAX_CONTEXTS];
     290} g_aContexts[VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX];
    299291
    300292/**
     
    407399
    408400#ifndef TESTCASE
     401    AssertReturn(pCtx, VERR_INVALID_POINTER);
     402    AssertReturn(pCtx->pAppContext, VERR_INVALID_POINTER);
     403
    409404    XtAppAddTimeOut(pCtx->pAppContext, 0, (XtTimerCallbackProc)proc,
    410405                    (XtPointer)client_data);
     
    884879            }
    885880
     881            LogRel(("Shared Clipboard: X11 event thread exiting\n"));
     882
    886883            clipUnregisterContext(pCtx);
     884        }
     885        else
     886        {
     887            LogRel(("Shared Clipboard: unable to register clip context: %Rrc\n", rc));
    887888        }
    888889
     
    12931294int ShClX11ThreadStop(PSHCLX11CTX pCtx)
    12941295{
     1296    int rc;
    12951297    /*
    12961298     * Immediately return if we are not connected to the X server.
     
    13021304
    13031305    /* Write to the "stop" pipe. */
    1304     clipThreadScheduleCall(pCtx, clipThreadSignalStop, (XtPointer)pCtx);
     1306    rc = clipThreadScheduleCall(pCtx, clipThreadSignalStop, (XtPointer)pCtx);
     1307    if (RT_FAILURE(rc))
     1308    {
     1309        LogRel(("Shared Clipboard: cannot notify X11 event thread on shutdown with %Rrc\n", rc));
     1310        return rc;
     1311    }
    13051312
    13061313    LogRel2(("Shared Clipboard: Waiting for X11 event thread to stop ...\n"));
    13071314
    13081315    int rcThread;
    1309     int rc = RTThreadWait(pCtx->Thread, RT_MS_30SEC /* msTimeout */, &rcThread);
     1316    rc = RTThreadWait(pCtx->Thread, RT_MS_30SEC /* msTimeout */, &rcThread);
    13101317    if (RT_SUCCESS(rc))
    13111318        rc = rcThread;
     
    18701877        rc = clipThreadScheduleCall(pCtx, ShClX11ReportFormatsToX11Worker,
    18711878                                    (XtPointer)pFormats);
     1879        if (RT_FAILURE(rc))
     1880            RTMemFree(pFormats);
    18721881    }
    18731882    else
     
    22742283        /* We use this to schedule a worker function on the event thread. */
    22752284        rc = clipThreadScheduleCall(pCtx, ShClX11ReadDataFromX11Worker, (XtPointer)pX11Req);
     2285        if (RT_FAILURE(rc))
     2286            RTMemFree(pX11Req);
    22762287    }
    22772288    else
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp

    r87686 r89947  
    2727#include <iprt/semaphore.h>
    2828#include <iprt/string.h>
     29#include <iprt/asm.h>
    2930
    3031#include <VBox/GuestHost/SharedClipboard.h>
     
    3536#include "VBoxSharedClipboardSvc-internal.h"
    3637
     38/* Number of currently extablished connections. */
     39static volatile uint32_t g_cShClConnections;
    3740
    3841/*********************************************************************************************************************************
     
    7679    int rc;
    7780
     81    /* Check if maximum allowed connections count has reached. */
     82    if (ASMAtomicIncU32(&g_cShClConnections) > VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX)
     83    {
     84        ASMAtomicDecU32(&g_cShClConnections);
     85        LogRel(("Shared Clipboard: maximum amount for client connections reached\n"));
     86        return VERR_OUT_OF_RESOURCES;
     87    }
     88
    7889    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)RTMemAllocZ(sizeof(SHCLCONTEXT));
    7990    if (pCtx)
     
    96107                RTCritSectDelete(&pCtx->CritSect);
    97108        }
    98         else
     109
     110        if (RT_FAILURE(rc))
     111        {
     112            pClient->State.pCtx = NULL;
    99113            RTMemFree(pCtx);
     114        }
    100115    }
    101116    else
    102117        rc = VERR_NO_MEMORY;
     118
     119    if (RT_FAILURE(rc))
     120    {
     121        /* Restore active connections count. */
     122        ASMAtomicDecU32(&g_cShClConnections);
     123    }
    103124
    104125    LogFlowFuncLeaveRC(rc);
     
    141162
    142163    RTMemFree(pCtx);
     164
     165    /* Decrease active connections count. */
     166    ASMAtomicDecU32(&g_cShClConnections);
    143167
    144168    LogFlowFuncLeaveRC(rc);
     
    253277    LogFlowFunc(("pCtx=%p, fFormats=%#x\n", pCtx, fFormats));
    254278
     279    int rc = VINF_SUCCESS;
    255280    PSHCLCLIENT pClient = pCtx->pClient;
    256281    AssertPtr(pClient);
    257282
    258     RTCritSectEnter(&pClient->CritSect);
    259 
    260     /** @todo r=bird: BUGBUG: Revisit this   */
    261     if (fFormats == VBOX_SHCL_FMT_NONE) /* No formats to report? Bail out early. */
    262         return;
    263 
    264     int rc = ShClSvcHostReportFormats(pCtx->pClient, fFormats);
    265     RT_NOREF(rc);
    266 
    267     RTCritSectLeave(&pClient->CritSect);
     283    rc = RTCritSectEnter(&pClient->CritSect);
     284    if (RT_SUCCESS(rc))
     285    {
     286        /** @todo r=bird: BUGBUG: Revisit this   */
     287        if (fFormats != VBOX_SHCL_FMT_NONE) /* No formats to report? */
     288        {
     289            rc = ShClSvcHostReportFormats(pCtx->pClient, fFormats);
     290        }
     291
     292        RTCritSectLeave(&pClient->CritSect);
     293    }
    268294
    269295    LogFlowFuncLeaveRC(rc);
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r89555 r89947  
    19951995    if (RT_SUCCESS(rc))
    19961996    {
     1997        /* Assign weak pointer to client map .*/
     1998        g_mapClients[u32ClientID] = pClient; /** @todo Handle OOM / collisions? */
     1999
    19972000        rc = ShClBackendConnect(pClient, ShClSvcGetHeadless());
    19982001        if (RT_SUCCESS(rc))
     
    20142017            if (RT_SUCCESS(rc))
    20152018            {
    2016                 /* Assign weak pointer to client map .*/
    2017                 g_mapClients[u32ClientID] = pClient; /** @todo Handle OOM / collisions? */
    2018 
    20192019                /* For now we ASSUME that the first client ever connected is in charge for
    20202020                 * communicating withe the service extension.
     
    20252025            }
    20262026        }
     2027
     2028        if (RT_FAILURE(rc))
     2029        {
     2030            shClSvcClientDestroy(pClient);
     2031        }
     2032
    20272033    }
    20282034
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