VirtualBox

Ignore:
Timestamp:
Jun 29, 2021 10:42:28 AM (4 years ago)
Author:
vboxsync
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/src/VBox/HostServices/SharedClipboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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