VirtualBox

Changeset 73662 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Aug 14, 2018 4:13:43 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/ASN.1: Added g_RTAsn1EFenceAllocator and RTAsn1CursorIsEnd.

Location:
trunk/src/VBox/Runtime/common/asn1
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/asn1/asn1-cursor.cpp

    r69111 r73662  
    184184    va_end(va);
    185185    return rc;
     186}
     187
     188
     189RTDECL(bool) RTAsn1CursorIsEnd(PRTASN1CURSOR pCursor)
     190{
     191    return pCursor->cbLeft == 0;
    186192}
    187193
  • trunk/src/VBox/Runtime/common/asn1/asn1-safer-allocator.cpp

    r73643 r73662  
    11/* $Id$ */
    22/** @file
    3  * IPRT - ASN.1, Default Allocator.
     3 * IPRT - ASN.1, Safer Allocator, for sensitive data.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#include <iprt/asn1.h>
    3333
    34 #include <iprt/mem.h>
     34#include <iprt/memsafer.h>
    3535#include <iprt/err.h>
    3636#include <iprt/string.h>
     
    4343 * @param   cb                  Requested size.
    4444 */
    45 static size_t rtAsn1DefaultAllocator_AlignSize(size_t cb)
     45static size_t rtAsn1SaferAllocator_AlignSize(size_t cb)
    4646{
    4747    if (cb >= 64)
     
    5656
    5757/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnFree} */
    58 static DECLCALLBACK(void) rtAsn1DefaultAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv)
    59 {
    60     RT_NOREF_PV(pThis);
    61     RTMemFree(pv);
     58static DECLCALLBACK(void) rtAsn1SaferAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv)
     59{
     60    RT_NOREF_PV(pThis);
     61    RTMemSaferFree(pv, pAllocation->cbAllocated);
    6262    pAllocation->cbAllocated = 0;
    6363}
     
    6565
    6666/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnAlloc} */
    67 static DECLCALLBACK(int)  rtAsn1DefaultAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
    68                                                        void **ppv, size_t cb)
    69 {
    70     size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cb);
    71     void *pv = RTMemAllocZ(cbAlloc);
     67static DECLCALLBACK(int)  rtAsn1SaferAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
     68                                                     void **ppv, size_t cb)
     69{
     70    size_t cbAlloc = rtAsn1SaferAllocator_AlignSize(cb);
     71    void *pv = RTMemSaferAllocZ(cbAlloc);
    7272    if (pv)
    7373    {
     
    8282
    8383/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnRealloc} */
    84 static DECLCALLBACK(int)  rtAsn1DefaultAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
    85                                                          void *pvOld, void **ppvNew, size_t cbNew)
     84static DECLCALLBACK(int)  rtAsn1SaferAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
     85                                                       void *pvOld, void **ppvNew, size_t cbNew)
    8686{
    8787    Assert(pvOld);
    8888    Assert(cbNew);
    89     size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cbNew);
    90     void *pv = RTMemRealloc(pvOld, cbAlloc);
     89    size_t cbAlloc = rtAsn1SaferAllocator_AlignSize(cbNew);
     90    void *pv = RTMemSaferReallocZ(pAllocation->cbAllocated, pvOld, cbAlloc);
    9191    if (pv)
    9292    {
     
    101101
    102102/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnFreeArray} */
    103 static DECLCALLBACK(void) rtAsn1DefaultAllocator_FreeArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
    104                                                            void **papvArray)
     103static DECLCALLBACK(void) rtAsn1SaferAllocator_FreeArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
     104                                                         void **papvArray)
    105105{
    106106    RT_NOREF_PV(pThis);
     
    110110    uint32_t i = pAllocation->cEntriesAllocated;
    111111    while (i-- > 0)
    112         RTMemFree(papvArray[i]);
     112        RTMemSaferFree(papvArray[i], pAllocation->cbEntry);
    113113    RTMemFree(papvArray);
    114114
     
    119119
    120120/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnGrowArray} */
    121 static DECLCALLBACK(int) rtAsn1DefaultAllocator_GrowArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
     121static DECLCALLBACK(int) rtAsn1SaferAllocator_GrowArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
    122122                                                          void ***ppapvArray, uint32_t cMinEntries)
    123123{
     
    173173    {
    174174        void *pv;
    175         papvArray[pAllocation->cEntriesAllocated] = pv = RTMemAllocZ(pAllocation->cbEntry);
     175        papvArray[pAllocation->cEntriesAllocated] = pv = RTMemSaferAllocZ(pAllocation->cbEntry);
    176176        if (pv)
    177177            pAllocation->cEntriesAllocated++;
     
    187187
    188188/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnShrinkArray} */
    189 static DECLCALLBACK(void) rtAsn1DefaultAllocator_ShrinkArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
     189static DECLCALLBACK(void) rtAsn1SaferAllocator_ShrinkArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
    190190                                                             void ***ppapvArray, uint32_t cNew, uint32_t cCurrent)
    191191{
     
    198198    while (cNew < cCurrent)
    199199    {
     200        RTMemWipeThoroughly(papvArray[cNew], pAllocation->cbEntry, 3);
    200201        RT_BZERO(papvArray[cNew], pAllocation->cbEntry);
    201202        cNew++;
     
    205206
    206207
    207 /** The default ASN.1 allocator. */
     208/** The Safer ASN.1 allocator. */
    208209#if 1 || !defined(IN_RING3) || defined(DOXYGEN_RUNNING)
    209 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocator =
     210RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocator =
    210211#else
    211 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocatorDisabled =
     212RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocatorDisabled =
    212213#endif
    213214{
    214     rtAsn1DefaultAllocator_Free,
    215     rtAsn1DefaultAllocator_Alloc,
    216     rtAsn1DefaultAllocator_Realloc,
    217     rtAsn1DefaultAllocator_FreeArray,
    218     rtAsn1DefaultAllocator_GrowArray,
    219     rtAsn1DefaultAllocator_ShrinkArray
     215    rtAsn1SaferAllocator_Free,
     216    rtAsn1SaferAllocator_Alloc,
     217    rtAsn1SaferAllocator_Realloc,
     218    rtAsn1SaferAllocator_FreeArray,
     219    rtAsn1SaferAllocator_GrowArray,
     220    rtAsn1SaferAllocator_ShrinkArray
    220221};
    221222
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