Changeset 73662 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Aug 14, 2018 4:13:43 PM (6 years ago)
- 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 184 184 va_end(va); 185 185 return rc; 186 } 187 188 189 RTDECL(bool) RTAsn1CursorIsEnd(PRTASN1CURSOR pCursor) 190 { 191 return pCursor->cbLeft == 0; 186 192 } 187 193 -
trunk/src/VBox/Runtime/common/asn1/asn1-safer-allocator.cpp
r73643 r73662 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - ASN.1, Default Allocator.3 * IPRT - ASN.1, Safer Allocator, for sensitive data. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #include <iprt/asn1.h> 33 33 34 #include <iprt/mem .h>34 #include <iprt/memsafer.h> 35 35 #include <iprt/err.h> 36 36 #include <iprt/string.h> … … 43 43 * @param cb Requested size. 44 44 */ 45 static size_t rtAsn1 DefaultAllocator_AlignSize(size_t cb)45 static size_t rtAsn1SaferAllocator_AlignSize(size_t cb) 46 46 { 47 47 if (cb >= 64) … … 56 56 57 57 /** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnFree} */ 58 static DECLCALLBACK(void) rtAsn1 DefaultAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv)59 { 60 RT_NOREF_PV(pThis); 61 RTMem Free(pv);58 static DECLCALLBACK(void) rtAsn1SaferAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv) 59 { 60 RT_NOREF_PV(pThis); 61 RTMemSaferFree(pv, pAllocation->cbAllocated); 62 62 pAllocation->cbAllocated = 0; 63 63 } … … 65 65 66 66 /** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnAlloc} */ 67 static DECLCALLBACK(int) rtAsn1 DefaultAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,68 69 { 70 size_t cbAlloc = rtAsn1 DefaultAllocator_AlignSize(cb);71 void *pv = RTMem AllocZ(cbAlloc);67 static 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); 72 72 if (pv) 73 73 { … … 82 82 83 83 /** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnRealloc} */ 84 static DECLCALLBACK(int) rtAsn1 DefaultAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,85 84 static DECLCALLBACK(int) rtAsn1SaferAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, 85 void *pvOld, void **ppvNew, size_t cbNew) 86 86 { 87 87 Assert(pvOld); 88 88 Assert(cbNew); 89 size_t cbAlloc = rtAsn1 DefaultAllocator_AlignSize(cbNew);90 void *pv = RTMem Realloc(pvOld, cbAlloc);89 size_t cbAlloc = rtAsn1SaferAllocator_AlignSize(cbNew); 90 void *pv = RTMemSaferReallocZ(pAllocation->cbAllocated, pvOld, cbAlloc); 91 91 if (pv) 92 92 { … … 101 101 102 102 /** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnFreeArray} */ 103 static DECLCALLBACK(void) rtAsn1 DefaultAllocator_FreeArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,104 103 static DECLCALLBACK(void) rtAsn1SaferAllocator_FreeArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation, 104 void **papvArray) 105 105 { 106 106 RT_NOREF_PV(pThis); … … 110 110 uint32_t i = pAllocation->cEntriesAllocated; 111 111 while (i-- > 0) 112 RTMem Free(papvArray[i]);112 RTMemSaferFree(papvArray[i], pAllocation->cbEntry); 113 113 RTMemFree(papvArray); 114 114 … … 119 119 120 120 /** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnGrowArray} */ 121 static DECLCALLBACK(int) rtAsn1 DefaultAllocator_GrowArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,121 static DECLCALLBACK(int) rtAsn1SaferAllocator_GrowArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation, 122 122 void ***ppapvArray, uint32_t cMinEntries) 123 123 { … … 173 173 { 174 174 void *pv; 175 papvArray[pAllocation->cEntriesAllocated] = pv = RTMem AllocZ(pAllocation->cbEntry);175 papvArray[pAllocation->cEntriesAllocated] = pv = RTMemSaferAllocZ(pAllocation->cbEntry); 176 176 if (pv) 177 177 pAllocation->cEntriesAllocated++; … … 187 187 188 188 /** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnShrinkArray} */ 189 static DECLCALLBACK(void) rtAsn1 DefaultAllocator_ShrinkArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,189 static DECLCALLBACK(void) rtAsn1SaferAllocator_ShrinkArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation, 190 190 void ***ppapvArray, uint32_t cNew, uint32_t cCurrent) 191 191 { … … 198 198 while (cNew < cCurrent) 199 199 { 200 RTMemWipeThoroughly(papvArray[cNew], pAllocation->cbEntry, 3); 200 201 RT_BZERO(papvArray[cNew], pAllocation->cbEntry); 201 202 cNew++; … … 205 206 206 207 207 /** The defaultASN.1 allocator. */208 /** The Safer ASN.1 allocator. */ 208 209 #if 1 || !defined(IN_RING3) || defined(DOXYGEN_RUNNING) 209 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1 DefaultAllocator =210 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocator = 210 211 #else 211 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1 DefaultAllocatorDisabled =212 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocatorDisabled = 212 213 #endif 213 214 { 214 rtAsn1 DefaultAllocator_Free,215 rtAsn1 DefaultAllocator_Alloc,216 rtAsn1 DefaultAllocator_Realloc,217 rtAsn1 DefaultAllocator_FreeArray,218 rtAsn1 DefaultAllocator_GrowArray,219 rtAsn1 DefaultAllocator_ShrinkArray215 rtAsn1SaferAllocator_Free, 216 rtAsn1SaferAllocator_Alloc, 217 rtAsn1SaferAllocator_Realloc, 218 rtAsn1SaferAllocator_FreeArray, 219 rtAsn1SaferAllocator_GrowArray, 220 rtAsn1SaferAllocator_ShrinkArray 220 221 }; 221 222
Note:
See TracChangeset
for help on using the changeset viewer.