VirtualBox

Ignore:
Timestamp:
Dec 15, 2016 3:26:20 PM (8 years ago)
Author:
vboxsync
Message:

IPRT/ASN.1: Refactored array handling (SET OF, SEQUENCE OF) to use a pointer array instead of an object instance array. The old approach would move objects around in memory after they'd be initialized/decoded, making certain core optimziations involving pointers to object members impossible, as well as causing potentially causing trouble when modifying structures that takes down pointers after decoding. Fixed validation bug in rtCrX509Name_CheckSanityExtra where it didn't check that the RDNs had subitems but instead checked the parent twice (slight risk).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asn1-generator-pass.h

    r62583 r64883  
    372372# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, a_OfApi, a_OfMember) \
    373373    RTASN1TMPL_BEGIN_COMMON(); \
    374     RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
     374    RTAsn1MemInitArrayAllocation(&pThis->Allocation, pAllocator, sizeof(a_ItemType)); \
    375375    int rc = RT_CONCAT(a_OfApi,_Init)(&pThis->a_OfMember, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)); \
    376376    if (RT_FAILURE(rc)) \
     
    555555        pCursor = &ThisCursor; \
    556556        pThis->a_OfMember.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable); \
    557         RTAsn1CursorInitAllocation(pCursor, &pThis->Allocation); \
     557        RTAsn1CursorInitArrayAllocation(pCursor, &pThis->Allocation, sizeof(a_ItemType)); \
    558558        \
    559559        uint32_t i = 0; \
     
    561561               && RT_SUCCESS(rc)) \
    562562        { \
    563             rc = RTAsn1MemGrowArray(&pThis->Allocation, \
    564                                     (void **)&pThis->paItems, \
    565                                     sizeof(pThis->paItems[0]), \
    566                                     i, \
    567                                     i + 1); \
     563            rc = RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, i, i + 1); \
    568564            if (RT_SUCCESS(rc)) \
    569565            { \
    570                 rc = RT_CONCAT(a_ItemApi,_DecodeAsn1)(pCursor, 0, &pThis->paItems[i], "paItems[#]"); \
     566                rc = RT_CONCAT(a_ItemApi,_DecodeAsn1)(pCursor, 0, pThis->papItems[i], "papItems[#]"); \
    571567                if (RT_SUCCESS(rc)) \
    572568                { \
     
    663659    RTASN1TMPL_BEGIN_COMMON(); \
    664660    for (uint32_t i = 0; i < pThis->cItems && rc == VINF_SUCCESS; i++) \
    665         rc = pfnCallback(RT_CONCAT(a_ItemApi,_GetAsn1Core)(&pThis->paItems[i]), "paItems[#]", uDepth, pvUser); \
     661        rc = pfnCallback(RT_CONCAT(a_ItemApi,_GetAsn1Core)(pThis->papItems[i]), "papItems[#]", uDepth, pvUser); \
    666662    RTASN1TMPL_END_COMMON()
    667663# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
     
    773769    if (RT_SUCCESS(rc)) \
    774770    { \
    775         RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
     771        RTAsn1MemInitArrayAllocation(&pThis->Allocation, pAllocator, sizeof(a_ItemType)); \
    776772        uint32_t const cItems = pSrc->cItems; \
    777773        if (cItems > 0) \
    778774        { \
    779             rc = RTAsn1MemGrowArray(&pThis->Allocation, (void **)&pThis->paItems, sizeof(pThis->paItems[0]), 0, cItems); \
     775            rc = RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, 0, cItems); \
    780776            if (RT_SUCCESS(rc)) \
    781777            { \
     
    783779                while (i < cItems) \
    784780                { \
    785                     rc = RT_CONCAT(a_ItemApi,_Clone)(&pThis->paItems[i], &pSrc->paItems[i], pAllocator); \
     781                    rc = RT_CONCAT(a_ItemApi,_Clone)(pThis->papItems[i], pSrc->papItems[i], pAllocator); \
    786782                    if (RT_SUCCESS(rc)) \
    787783                        pThis->cItems = ++i; \
     
    990986    if (cItems == pRight->cItems) \
    991987        for (uint32_t i = 0; iDiff == 0 && i < cItems; i++) \
    992             iDiff = RT_CONCAT(a_ItemApi,_Compare)(&pLeft->paItems[i], &pRight->paItems[i]); \
     988            iDiff = RT_CONCAT(a_ItemApi,_Compare)(pLeft->papItems[i], pRight->papItems[i]); \
    993989    else \
    994990        iDiff = cItems < pRight->cItems ? -1 : 1; \
     
    11351131    RTASN1TMPL_BEGIN_COMMON(); \
    11361132    for (uint32_t i = 0; RT_SUCCESS(rc) && i < pThis->cItems; i++) \
    1137         rc = RT_CONCAT(a_ItemApi,_CheckSanity)(&pThis->paItems[i], fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
    1138                                                pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::paItems[#]"); \
     1133        rc = RT_CONCAT(a_ItemApi,_CheckSanity)(pThis->papItems[i], fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
     1134                                               pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::papItems[#]"); \
    11391135    if (RT_SUCCESS(rc)) { RTASN1TMPL_SET_SEQ_EXEC_CHECK_SANITY(); } \
    11401136    RTASN1TMPL_END_COMMON()
     
    12691265    uint32_t i = pThis->cItems; \
    12701266    while (i-- > 0) \
    1271         RT_CONCAT(a_ItemApi,_Delete)(&pThis->paItems[i]); \
    1272     RTAsn1MemFree(&pThis->Allocation, pThis->paItems); \
    1273     pThis->paItems = NULL; \
     1267        RT_CONCAT(a_ItemApi,_Delete)(pThis->papItems[i]); \
     1268    RTAsn1MemFreeArray(&pThis->Allocation, (void **)pThis->papItems); \
     1269    pThis->papItems = NULL; \
     1270    pThis->cItems   = 0; \
    12741271    RTASN1TMPL_END_COMMON()
    12751272# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
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