- Timestamp:
- Oct 7, 2018 7:23:14 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asn1.h
r74295 r74657 595 595 * frequently used values. */ 596 596 #define RTASN1CORE_F_DECODED_CONTENT RT_BIT_32(6) 597 /** Indefinite length, still pending. */ 598 #define RTASN1CORE_F_INDEFINITE_LENGTH RT_BIT_32(7) 597 599 /** @} */ 598 600 … … 1647 1649 /** The cursor depth. */ 1648 1650 uint8_t cDepth; 1651 /** Number of pending indefinite length records. */ 1652 uint8_t cIndefinedRecs; 1649 1653 /** Two bytes reserved for future tricks. */ 1650 uint8_t abReserved[ 2];1654 uint8_t abReserved[1]; 1651 1655 /** Pointer to the primary cursor. */ 1652 1656 struct RTASN1CURSORPRIMARY *pPrimary; … … 1660 1664 * @{ */ 1661 1665 /** Enforce DER rules. */ 1662 #define RTASN1CURSOR_FLAGS_DER RT_BIT(1)1666 #define RTASN1CURSOR_FLAGS_DER RT_BIT(1) 1663 1667 /** Enforce CER rules. */ 1664 #define RTASN1CURSOR_FLAGS_CER RT_BIT(2) 1668 #define RTASN1CURSOR_FLAGS_CER RT_BIT(2) 1669 /** Pending indefinite length encoding. */ 1670 #define RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH RT_BIT(3) 1665 1671 /** @} */ 1666 1672 -
trunk/src/VBox/Runtime/common/asn1/asn1-cursor.cpp
r74656 r74657 32 32 #include <iprt/asn1.h> 33 33 34 #include <iprt/asm.h> 34 35 #include <iprt/alloca.h> 35 36 #include <iprt/err.h> … … 67 68 pPrimaryCursor->Cursor.fFlags = (uint8_t)fFlags; Assert(fFlags <= UINT8_MAX); 68 69 pPrimaryCursor->Cursor.cDepth = 0; 70 pPrimaryCursor->Cursor.cIndefinedRecs = 0; 69 71 pPrimaryCursor->Cursor.abReserved[0] = 0; 70 pPrimaryCursor->Cursor.abReserved[1] = 0;71 72 pPrimaryCursor->Cursor.pPrimary = pPrimaryCursor; 72 73 pPrimaryCursor->Cursor.pUp = NULL; … … 85 86 pChild->pbCur = pParent->pbCur; 86 87 pChild->cbLeft = cb; 87 pChild->fFlags = pParent->fFlags ;88 pChild->fFlags = pParent->fFlags & ~RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH; 88 89 pChild->cDepth = pParent->cDepth + 1; 89 90 AssertReturn(pChild->cDepth < RTASN1_MAX_NESTING, VERR_ASN1_TOO_DEEPLY_NESTED); 91 pChild->cIndefinedRecs = 0; 90 92 pChild->abReserved[0] = 0; 91 pChild->abReserved[1] = 0;92 93 pChild->pPrimary = pParent->pPrimary; 93 94 pChild->pUp = pParent; … … 110 111 pChild->pbCur = pAsn1Core->uData.pu8; 111 112 pChild->cbLeft = pAsn1Core->cb; 112 pChild->fFlags = pParent->fFlags ;113 pChild->fFlags = pParent->fFlags & ~RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH; 113 114 pChild->cDepth = pParent->cDepth + 1; 114 115 AssertReturn(pChild->cDepth < RTASN1_MAX_NESTING, VERR_ASN1_TOO_DEEPLY_NESTED); 116 pChild->cIndefinedRecs = 0; 115 117 pChild->abReserved[0] = 0; 116 pChild->abReserved[1] = 0;117 118 pChild->pPrimary = pParent->pPrimary; 118 119 pChild->pUp = pParent; … … 189 190 RTDECL(bool) RTAsn1CursorIsEnd(PRTASN1CURSOR pCursor) 190 191 { 191 return pCursor->cbLeft == 0; 192 if (pCursor->cbLeft == 0) 193 return true; 194 if (!(pCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH)) 195 return false; 196 /* This isn't quite right. */ 197 if (pCursor->cbLeft > pCursor->cIndefinedRecs * (uint32_t)2) 198 return false; 199 return ASMMemIsZero(pCursor->pbCur, pCursor->cbLeft); 192 200 } 193 201 … … 196 204 { 197 205 if (pCursor->cbLeft == 0) 206 return VINF_SUCCESS; 207 if ( (pCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH) 208 && pCursor->cbLeft == pCursor->cIndefinedRecs * (uint32_t)2 209 && ASMMemIsZero(pCursor->pbCur, pCursor->cbLeft)) 198 210 return VINF_SUCCESS; 199 211 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, … … 316 328 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_INDEFINITE_LENGTH, 317 329 "%s: Indefinite length form not allowed in DER mode (uTag=%#x).", pszErrorTag, uTag); 330 else if (!(uTag & ASN1_TAGFLAG_CONSTRUCTED)) 331 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, 332 "%s: Indefinite BER/CER encoding is for non-constructed tag (uTag=%#x)", pszErrorTag, uTag); 333 else if ( uTag != (ASN1_TAG_SEQUENCE | ASN1_TAGFLAG_CONSTRUCTED) 334 && uTag != (ASN1_TAG_SET | ASN1_TAGFLAG_CONSTRUCTED) 335 && (uTag & (ASN1_TAGFLAG_CONSTRUCTED | ASN1_TAGCLASS_CONTEXT)) 336 != (ASN1_TAGFLAG_CONSTRUCTED | ASN1_TAGCLASS_CONTEXT) ) 337 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, 338 "%s: Indefinite BER/CER encoding not supported for this tag (uTag=%#x)", pszErrorTag, uTag); 339 else if (pCursor->cIndefinedRecs > 8) 340 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, 341 "%s: Too many indefinite BER/CER encodings. (uTag=%#x)", pszErrorTag, uTag); 318 342 else if (pCursor->cbLeft < 2) 319 343 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, … … 321 345 else 322 346 { 323 /* Search forward till we find the two terminating zero bytes. */ 324 cb = 0; 325 for (;;) 326 { 327 uint8_t const *pb = (uint8_t const *)memchr(&pCursor->pbCur[cb], 0x00, pCursor->cbLeft - cb - 1); 328 if (pb && pb[1] == 0x00) 329 { 330 cb = &pb[2] - pCursor->pbCur; 331 break; 332 } 333 if (!pb) 334 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, 335 "%s: Could not find end of indefinite BER/CER record (uTag=%#x)", pszErrorTag, uTag); 336 cb = &pb[1] - pCursor->pbCur; 337 } 347 pCursor->cIndefinedRecs++; 348 pCursor->fFlags |= RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH; 349 pAsn1Core->fFlags |= RTASN1CORE_F_INDEFINITE_LENGTH; 350 cb = pCursor->cbLeft - pCursor->cIndefinedRecs * 2; /* tentatively */ 338 351 } 339 352 }
Note:
See TracChangeset
for help on using the changeset viewer.