Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: nss/lib/util/secasn1d.c

Issue 1504923011: Update NSS to 3.21 RTM and NSPR to 4.11 RTM (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 /* 5 /*
6 * Support for DEcoding ASN.1 data based on BER/DER (Basic/Distinguished 6 * Support for DEcoding ASN.1 data based on BER/DER (Basic/Distinguished
7 * Encoding Rules). 7 * Encoding Rules).
8 */ 8 */
9 9
10 /* #define DEBUG_ASN1D_STATES 1 */ 10 /* #define DEBUG_ASN1D_STATES 1 */
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 *remaining -= consumed; 978 *remaining -= consumed;
979 return PR_TRUE; 979 return PR_TRUE;
980 } 980 }
981 981
982 static void 982 static void
983 sec_asn1d_prepare_for_contents (sec_asn1d_state *state) 983 sec_asn1d_prepare_for_contents (sec_asn1d_state *state)
984 { 984 {
985 SECItem *item; 985 SECItem *item;
986 PLArenaPool *poolp; 986 PLArenaPool *poolp;
987 unsigned long alloc_len; 987 unsigned long alloc_len;
988 sec_asn1d_state *parent;
988 989
989 #ifdef DEBUG_ASN1D_STATES 990 #ifdef DEBUG_ASN1D_STATES
990 { 991 {
991 printf("Found Length %d %s\n", state->contents_length, 992 printf("Found Length %d %s\n", state->contents_length,
992 state->indefinite ? "indefinite" : ""); 993 state->indefinite ? "indefinite" : "");
993 } 994 }
994 #endif 995 #endif
995 996
996 /** 997 /**
997 * The maximum length for a child element should be constrained to the 998 * The maximum length for a child element should be constrained to the
(...skipping 15 matching lines...) Expand all
1013 * elements that may have been read). 1014 * elements that may have been read).
1014 * 1015 *
1015 * It's slightly complicated by the need to account both for integer 1016 * It's slightly complicated by the need to account both for integer
1016 * underflow and overflow, as well as ensure that for indefinite length 1017 * underflow and overflow, as well as ensure that for indefinite length
1017 * encodings, there's also enough space for the End-of-Contents (EOC) 1018 * encodings, there's also enough space for the End-of-Contents (EOC)
1018 * octets (Tag = 0x00, Length = 0x00, or two bytes). 1019 * octets (Tag = 0x00, Length = 0x00, or two bytes).
1019 */ 1020 */
1020 1021
1021 /* Determine the maximum length available for this element by finding the 1022 /* Determine the maximum length available for this element by finding the
1022 * first definite length ancestor, if any. */ 1023 * first definite length ancestor, if any. */
1023 sec_asn1d_state *parent = sec_asn1d_get_enclosing_construct(state); 1024 parent = sec_asn1d_get_enclosing_construct(state);
1024 while (parent && parent->indefinite) { 1025 while (parent && parent->indefinite) {
1025 parent = sec_asn1d_get_enclosing_construct(parent); 1026 parent = sec_asn1d_get_enclosing_construct(parent);
1026 } 1027 }
1027 /* If parent is null, state is either the outermost state / at the top of 1028 /* If parent is null, state is either the outermost state / at the top of
1028 * the stack, or the outermost state uses indefinite length encoding. In 1029 * the stack, or the outermost state uses indefinite length encoding. In
1029 * these cases, there's nothing external to constrain this element, so 1030 * these cases, there's nothing external to constrain this element, so
1030 * there's nothing to check. */ 1031 * there's nothing to check. */
1031 if (parent) { 1032 if (parent) {
1032 unsigned long remaining = parent->pending; 1033 unsigned long remaining = parent->pending;
1033 parent = state; 1034 parent = state;
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 if (child_consumed > state->pending) { 1783 if (child_consumed > state->pending) {
1783 PORT_SetError (SEC_ERROR_BAD_DER); 1784 PORT_SetError (SEC_ERROR_BAD_DER);
1784 state->top->status = decodeError; 1785 state->top->status = decodeError;
1785 return; 1786 return;
1786 } 1787 }
1787 1788
1788 state->pending -= child_consumed; 1789 state->pending -= child_consumed;
1789 if (state->pending == 0) 1790 if (state->pending == 0)
1790 done = PR_TRUE; 1791 done = PR_TRUE;
1791 } else { 1792 } else {
1793 PRBool preallocatedString;
1794 sec_asn1d_state *temp_state;
1792 PORT_Assert (state->indefinite); 1795 PORT_Assert (state->indefinite);
1793 1796
1794 item = (SECItem *)(child->dest); 1797 item = (SECItem *)(child->dest);
1795 1798
1796 /** 1799 /**
1797 * At this point, there's three states at play: 1800 * At this point, there's three states at play:
1798 * child: The element that was just parsed 1801 * child: The element that was just parsed
1799 * state: The currently processed element 1802 * state: The currently processed element
1800 * 'parent' (aka state->parent): The enclosing construct 1803 * 'parent' (aka state->parent): The enclosing construct
1801 * of state, or NULL if this is the top-most element. 1804 * of state, or NULL if this is the top-most element.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 * any type, then the enclosing construct is either an any type (#3/#4) 1857 * any type, then the enclosing construct is either an any type (#3/#4)
1855 * or some other type (#5). Since this is BER, this nesting relationship 1858 * or some other type (#5). Since this is BER, this nesting relationship
1856 * between 'state' and 'parent' may go through several levels of 1859 * between 'state' and 'parent' may go through several levels of
1857 * constructed encoding, so continue walking the ancestor chain until a 1860 * constructed encoding, so continue walking the ancestor chain until a
1858 * clear determination can be made. 1861 * clear determination can be made.
1859 * 1862 *
1860 * The variable preallocatedString is used to indicate Case #1/#3, 1863 * The variable preallocatedString is used to indicate Case #1/#3,
1861 * indicating an in-place copy has already occurred, and Cases #2, #4, 1864 * indicating an in-place copy has already occurred, and Cases #2, #4,
1862 * and #5 all have the same behaviour of adding a new substring. 1865 * and #5 all have the same behaviour of adding a new substring.
1863 */ 1866 */
1864 » PRBool preallocatedString = PR_FALSE; 1867 » preallocatedString = PR_FALSE;
1865 » sec_asn1d_state *temp_state = state; 1868 » temp_state = state;
1866 while (temp_state && item == temp_state->dest && temp_state->indefinite) { 1869 while (temp_state && item == temp_state->dest && temp_state->indefinite) {
1867 sec_asn1d_state *parent = sec_asn1d_get_enclosing_construct(temp_sta te); 1870 sec_asn1d_state *parent = sec_asn1d_get_enclosing_construct(temp_sta te);
1868 if (!parent || parent->underlying_kind != temp_state->underlying_kin d) { 1871 if (!parent || parent->underlying_kind != temp_state->underlying_kin d) {
1869 /* Case #5 - Either this is a top-level construct or it is part 1872 /* Case #5 - Either this is a top-level construct or it is part
1870 * of some other element (e.g. a SEQUENCE), in which case, a 1873 * of some other element (e.g. a SEQUENCE), in which case, a
1871 * new item should be allocated. */ 1874 * new item should be allocated. */
1872 break; 1875 break;
1873 } 1876 }
1874 if (!parent->indefinite) { 1877 if (!parent->indefinite) {
1875 /* Cases #1 / #3 - A definite length ancestor exists, for which 1878 /* Cases #1 / #3 - A definite length ancestor exists, for which
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_EnumeratedTemplate) 3394 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_EnumeratedTemplate)
3392 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PointerToEnumeratedTemplate) 3395 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PointerToEnumeratedTemplate)
3393 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SequenceOfAnyTemplate) 3396 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SequenceOfAnyTemplate)
3394 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SequenceOfObjectIDTemplate) 3397 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SequenceOfObjectIDTemplate)
3395 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SkipTemplate) 3398 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SkipTemplate)
3396 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_UniversalStringTemplate) 3399 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_UniversalStringTemplate)
3397 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PrintableStringTemplate) 3400 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PrintableStringTemplate)
3398 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_T61StringTemplate) 3401 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_T61StringTemplate)
3399 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PointerToGeneralizedTimeTemplate) 3402 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PointerToGeneralizedTimeTemplate)
3400 3403
OLDNEW
« nss/lib/util/pkcs11n.h ('K') | « nss/lib/util/quickder.c ('k') | nss/lib/util/secoid.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698