VirtualBox

Changeset 64288 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Oct 17, 2016 9:42:49 AM (8 years ago)
Author:
vboxsync
Message:

RTLocalIpcMakeNameUniqueUser: build fix and @todo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/localipc.cpp

    r64287 r64288  
     1/* $Id$ */
    12/** @file
    2 * IPRT - defines the function to create ipc pipe name.
    3 */
     3 * IPRT - Implements RTLocalIpcMakeNameUniqueUser
     4 */
    45
    56/*
    6 * Copyright (C) 2010-2016 Oracle Corporation
    7 *
    8 * This file is part of VirtualBox Open Source Edition (OSE), as
    9 * available from http://www.virtualbox.org. This file is free software;
    10 * you can redistribute it and/or modify it under the terms of the GNU
    11 * General Public License (GPL) as published by the Free Software
    12 * Foundation, in version 2 as it comes in the "COPYING" file of the
    13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
    14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    15 *
    16 * The contents of this file may alternatively be used under the terms
    17 * of the Common Development and Distribution License Version 1.0
    18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
    19 * VirtualBox OSE distribution, in which case the provisions of the
    20 * CDDL are applicable instead of those of the GPL.
    21 *
    22 * You may elect to license modified versions of this file under the
    23 * terms and conditions of either the GPL or the CDDL or both.
    24 */
     7 * Copyright (C) 2010-2016 Oracle Corporation
     8 *
     9 * This file is part of VirtualBox Open Source Edition (OSE), as
     10 * available from http://www.virtualbox.org. This file is free software;
     11 * you can redistribute it and/or modify it under the terms of the GNU
     12 * General Public License (GPL) as published by the Free Software
     13 * Foundation, in version 2 as it comes in the "COPYING" file of the
     14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
     15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
     16 *
     17 * The contents of this file may alternatively be used under the terms
     18 * of the Common Development and Distribution License Version 1.0
     19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
     20 * VirtualBox OSE distribution, in which case the provisions of the
     21 * CDDL are applicable instead of those of the GPL.
     22 *
     23 * You may elect to license modified versions of this file under the
     24 * terms and conditions of either the GPL or the CDDL or both.
     25 */
    2526
    2627/*********************************************************************************************************************************
     
    3435
    3536/**
    36 * Make the IPC pipe name unique for user
    37 * in a form like 'VBoxTrayIPC-6a4500cb7c726949'
    38 *
    39 * @returns IPRT status code.
    40 * @retval  VINF_SUCCESS and *pcbDest if pipe name created successfully.
    41 * @retval  VERR_INVALID_PARAMETER in case of invalid parameter value.
    42 * @retval  VERR_BUFFER_OVERFLOW if the pszDest is too small.
    43 *
    44 * @param   pszPrefix        Pipe name prefix, for example 'VBoxTrayIPC-'
    45 * @param   pszUserName      User name
    46 * @param   pszDest          Destination buffer to store created pipe name
    47 * @param   pcbDest          IN  - size of destination buffer in bytes,
    48 *                           OUT - length of created pipe name in bytes without trailing zero
    49 */
    50 RTDECL(int) RTLocalIpcMakeNameUniqueUser(const char* pszPrefix, const char* pszUserName, char* pszDest, size_t* pcbDest)
     37 * Make the IPC pipe name unique for user
     38 * in a form like 'VBoxTrayIPC-6a4500cb7c726949'
     39 *
     40 * @returns IPRT status code.
     41 * @retval  VINF_SUCCESS and *pcbDst if pipe name created successfully.
     42 * @retval  VERR_INVALID_PARAMETER in case of invalid parameter value.
     43 * @retval  VERR_BUFFER_OVERFLOW if the pszDst is too small.
     44 *
     45 * @param   pszPrefix        Pipe name prefix, for example 'VBoxTrayIPC-'
     46 * @param   pszUsername      Username.
     47 * @param   pszDst           Destination buffer to store created pipe name
     48 * @param   pcbDst           IN  - size of destination buffer in bytes,
     49 *                           OUT - length of created pipe name in bytes without trailing zero
     50 *
     51 * @todo    r=bird: 'Unique' is a misnomer here.  Doing CRC64 on a string does
     52 *          not guarentee uniqueness, not even using cryptographic hashing will
     53 *          achive this.  There can be two @a pszUsername strings with the same
     54 *          CRC64 value, while still being different.
     55 *
     56 *          Rename the function to something like RTLocalIpcMakeAsciiName and
     57 *          use a safe escape-like recoding of it.
     58 *
     59 *          Also, pcbDst should be two parameters.
     60 */
     61RTDECL(int) RTLocalIpcMakeNameUniqueUser(const char *pszPrefix, const char *pszUsername, char *pszDst, size_t *pcbDst)
    5162{
    5263    AssertPtrReturn(pszPrefix, VERR_INVALID_PARAMETER);
    53     AssertPtrReturn(pszUserName, VERR_INVALID_PARAMETER);
    54     AssertPtrReturn(pcbDest, VERR_INVALID_PARAMETER);
    55     AssertReturn(*pcbDest, VERR_INVALID_PARAMETER);
    56     AssertPtrReturn(pszDest, VERR_INVALID_PARAMETER);
     64    AssertPtrReturn(pszUsername, VERR_INVALID_PARAMETER);
     65    AssertPtrReturn(pcbDst, VERR_INVALID_PARAMETER);
     66    AssertReturn(*pcbDst, VERR_BUFFER_OVERFLOW);
     67    AssertPtrReturn(pszDst, VERR_INVALID_PARAMETER);
    5768
    58     const size_t cbPrefixSize = RTStrNLen(pszPrefix, RTSTR_MAX);
    59     AssertReturn(*pcbDest > cbPrefixSize + 17, VERR_BUFFER_OVERFLOW);
     69    const size_t cchPrefix = strlen(pszPrefix);
     70    AssertReturn(*pcbDst > cchPrefix + 17, VERR_BUFFER_OVERFLOW);
    6071
    61     const size_t cbSourceSize = RTStrNLen(pszUserName, RTSTR_MAX);
    62     AssertReturn(cbSourceSize, VERR_INVALID_PARAMETER);
     72    const size_t cchSrc = strlen(pszUsername);
     73    AssertReturn(cchSrc, VERR_INVALID_PARAMETER);
    6374
    6475    /* Use the crc of user name instead of user name to avoid localized pipe problem */
    65     uint64_t uiCrc = RTCrc64(pszUserName, cbSourceSize);
    66     AssertReturn(uiCrc > 0, VERR_INVALID_PARAMETER);
     76    uint64_t uCrc = RTCrc64(pszUsername, cchSrc);
     77    AssertReturn(uCrc > 0, VERR_INVALID_PARAMETER);
    6778
    68     RT_BZERO(pszDest, *pcbDest);
    69     size_t cbRes = RTStrPrintf(pszDest, *pcbDest, "%s%016RX64", pszPrefix, uiCrc);
    70     AssertReturn(cbRes, VERR_BUFFER_OVERFLOW);
     79    RT_BZERO(pszDst, *pcbDst);
     80    size_t cbRes = RTStrPrintf(pszDst, *pcbDst, "%s%016RX64", pszPrefix, uCrc);
     81    AssertReturn(cbRes, VERR_BUFFER_OVERFLOW); /** @todo r=bird: WRONG. RTStrPrintf is a very very stupid API which is almost impossible to check for overflows */
    7182
    72     *pcbDest = cbRes;
     83    *pcbDst = cbRes;
    7384    return VINF_SUCCESS;
    7485}
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