Print out bad content octets.
[openssl.git] / crypto / asn1 / asn1_par.c
index 574e8de86704630c68441c171d2665b8571dc6e0..d0de27207a2ede1a756058d73146ba285544d8d9 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/asn1/asn1_par.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  */
 
 #include <stdio.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/buffer.h>
 #include <openssl/objects.h>
 #include <openssl/asn1.h>
 
+#ifndef ASN1_PARSE_MAXDEPTH
+#define ASN1_PARSE_MAXDEPTH 128
+#endif
+
 static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
                            int indent);
 static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
@@ -121,7 +124,12 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
     ASN1_OBJECT *o = NULL;
     ASN1_OCTET_STRING *os = NULL;
     /* ASN1_BMPSTRING *bmp=NULL; */
-    int dump_indent;
+    int dump_indent, dump_cont = 0;
+
+    if (depth > ASN1_PARSE_MAXDEPTH) {
+            BIO_puts(bp, "BAD RECURSION DEPTH\n");
+            return 0;
+    }
 
     dump_indent = 6;            /* Because we know BIO_dump_indent() */
     p = *pp;
@@ -213,11 +221,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
                 } else {
                     if (BIO_write(bp, ":BAD OBJECT", 11) <= 0)
                         goto end;
+                    dump_cont = 1;
                 }
             } else if (tag == V_ASN1_BOOLEAN) {
                 if (len != 1) {
-                    if (BIO_write(bp, "Bad boolean\n", 12) <= 0)
+                    if (BIO_puts(bp, "BAD BOOLEAN") <= 0)
                         goto end;
+                    dump_cont = 1;
                 }
                 BIO_printf(bp, ":%u", p[0]);
             } else if (tag == V_ASN1_BMPSTRING) {
@@ -301,6 +311,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
                 } else {
                     if (BIO_write(bp, "BAD INTEGER", 11) <= 0)
                         goto end;
+                    dump_cont = 1;
                 }
                 ASN1_INTEGER_free(bs);
             } else if (tag == V_ASN1_ENUMERATED) {
@@ -326,6 +337,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
                 } else {
                     if (BIO_write(bp, "BAD ENUMERATED", 14) <= 0)
                         goto end;
+                    dump_cont = 1;
                 }
                 ASN1_ENUMERATED_free(bs);
             } else if (len > 0 && dump) {
@@ -339,6 +351,18 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
                     goto end;
                 nl = 1;
             }
+            if (dump_cont) {
+                int i;
+                const unsigned char *tmp = op + hl;
+                if (BIO_puts(bp, ":[") <= 0)
+                    goto end;
+                for (i = 0; i < len; i++) {
+                    if (BIO_printf(bp, "%02X", tmp[i]) <= 0)
+                        goto end;
+                }
+                if (BIO_puts(bp, "]") <= 0)
+                    goto end;
+            }
 
             if (!nl) {
                 if (BIO_write(bp, "\n", 1) <= 0)