Changeset 64288 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Oct 17, 2016 9:42:49 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/localipc.cpp
r64287 r64288 1 /* $Id$ */ 1 2 /** @file 2 * IPRT - defines the function to create ipc pipe name. 3 */3 * IPRT - Implements RTLocalIpcMakeNameUniqueUser 4 */ 4 5 5 6 /* 6 * Copyright (C) 2010-2016 Oracle Corporation7 *8 * This file is part of VirtualBox Open Source Edition (OSE), as9 * 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 GNU11 * General Public License (GPL) as published by the Free Software12 * Foundation, in version 2 as it comes in the "COPYING" file of the13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the14 * 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 terms17 * of the Common Development and Distribution License Version 1.018 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the19 * VirtualBox OSE distribution, in which case the provisions of the20 * CDDL are applicable instead of those of the GPL.21 *22 * You may elect to license modified versions of this file under the23 * 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 */ 25 26 26 27 /********************************************************************************************************************************* … … 34 35 35 36 /** 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 */ 61 RTDECL(int) RTLocalIpcMakeNameUniqueUser(const char *pszPrefix, const char *pszUsername, char *pszDst, size_t *pcbDst) 51 62 { 52 63 AssertPtrReturn(pszPrefix, VERR_INVALID_PARAMETER); 53 AssertPtrReturn(pszUser Name, VERR_INVALID_PARAMETER);54 AssertPtrReturn(pcbD est, VERR_INVALID_PARAMETER);55 AssertReturn(*pcbD est, VERR_INVALID_PARAMETER);56 AssertPtrReturn(pszD est, 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); 57 68 58 const size_t c bPrefixSize = RTStrNLen(pszPrefix, RTSTR_MAX);59 AssertReturn(*pcbD est > cbPrefixSize+ 17, VERR_BUFFER_OVERFLOW);69 const size_t cchPrefix = strlen(pszPrefix); 70 AssertReturn(*pcbDst > cchPrefix + 17, VERR_BUFFER_OVERFLOW); 60 71 61 const size_t c bSourceSize = RTStrNLen(pszUserName, RTSTR_MAX);62 AssertReturn(c bSourceSize, VERR_INVALID_PARAMETER);72 const size_t cchSrc = strlen(pszUsername); 73 AssertReturn(cchSrc, VERR_INVALID_PARAMETER); 63 74 64 75 /* Use the crc of user name instead of user name to avoid localized pipe problem */ 65 uint64_t u iCrc = RTCrc64(pszUserName, cbSourceSize);66 AssertReturn(u iCrc > 0, VERR_INVALID_PARAMETER);76 uint64_t uCrc = RTCrc64(pszUsername, cchSrc); 77 AssertReturn(uCrc > 0, VERR_INVALID_PARAMETER); 67 78 68 RT_BZERO(pszD est, *pcbDest);69 size_t cbRes = RTStrPrintf(pszD est, *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 */ 71 82 72 *pcbD est = cbRes;83 *pcbDst = cbRes; 73 84 return VINF_SUCCESS; 74 85 }
Note:
See TracChangeset
for help on using the changeset viewer.