Missing declarations, no assembler in PEDANTIC.
[openssl.git] / crypto / asn1 / a_strex.c
index 7ddb7662f1e54f703781c03bae69b019f6dc6d5d..7fc14d3296c1ccb1db5b433b5c316375c265bfcc 100644 (file)
@@ -1,5 +1,5 @@
 /* a_strex.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
 /* ====================================================================
@@ -58,6 +58,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include "cryptlib.h"
 #include <openssl/crypto.h>
 #include <openssl/x509.h>
 #include <openssl/asn1.h>
@@ -114,14 +115,17 @@ typedef int char_io(void *arg, const void *buf, int len);
 static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg)
 {
        unsigned char chflgs, chtmp;
-       char tmphex[11];
+       char tmphex[HEX_SIZE(long)+3];
+
+       if(c > 0xffffffffL)
+               return -1;
        if(c > 0xffff) {
-               BIO_snprintf(tmphex, 11, "\\W%08lX", c);
+               BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c);
                if(!io_ch(arg, tmphex, 10)) return -1;
                return 10;
        }
        if(c > 0xff) {
-               BIO_snprintf(tmphex, 11, "\\U%04lX", c);
+               BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c);
                if(!io_ch(arg, tmphex, 6)) return -1;
                return 6;
        }
@@ -166,7 +170,7 @@ static int do_buf(unsigned char *buf, int buflen,
        q = buf + buflen;
        outlen = 0;
        while(p != q) {
-               if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
+               if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253;
                else orflags = 0;
                switch(type & BUF_TYPE_WIDTH_MASK) {
                        case 4:
@@ -190,12 +194,14 @@ static int do_buf(unsigned char *buf, int buflen,
                        if(i < 0) return -1;    /* Invalid UTF8String */
                        p += i;
                        break;
+                       default:
+                       return -1;      /* invalid width */
                }
-               if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
+               if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253;
                if(type & BUF_TYPE_CONVUTF8) {
                        unsigned char utfbuf[6];
                        int utflen;
-                       utflen = UTF8_putc(utfbuf, 6, c);
+                       utflen = UTF8_putc(utfbuf, sizeof utfbuf, c);
                        for(i = 0; i < utflen; i++) {
                                /* We don't need to worry about setting orflags correctly
                                 * because if utflen==1 its value will be correct anyway 
@@ -219,7 +225,7 @@ static int do_buf(unsigned char *buf, int buflen,
 
 static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
 {
-       const static char hexdig[] = "0123456789ABCDEF";
+       static const char hexdig[] = "0123456789ABCDEF";
        unsigned char *p, *q;
        char hextmp[2];
        if(arg) {
@@ -275,13 +281,13 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING
  * otherwise it is the number of bytes per character
  */
 
-const static char tag2nbyte[] = {
+static const signed char tag2nbyte[] = {
        -1, -1, -1, -1, -1,     /* 0-4 */
        -1, -1, -1, -1, -1,     /* 5-9 */
        -1, -1, 0, -1,          /* 10-13 */
        -1, -1, -1, -1,         /* 15-17 */
        -1, 1, 1,               /* 18-20 */
-       -1, 1, -1,-1,           /* 21-24 */
+       -1, 1, 1, 1,            /* 21-24 */
        -1, 1, -1,              /* 25-27 */
        4, -1, 2                /* 28-30 */
 };
@@ -352,12 +358,13 @@ static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STR
        }
 
        len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
-       if(outlen < 0) return -1;
+       if(len < 0) return -1;
        outlen += len;
        if(quotes) outlen += 2;
        if(!arg) return outlen;
        if(quotes && !io_ch(arg, "\"", 1)) return -1;
-       do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
+       if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0)
+               return -1;
        if(quotes && !io_ch(arg, "\"", 1)) return -1;
        return outlen;
 }
@@ -461,7 +468,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
                if(fn_opt != XN_FLAG_FN_NONE) {
                        int objlen, fld_len;
                        if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
-                               OBJ_obj2txt(objtmp, 80, fn, 1);
+                               OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1);
                                fld_len = 0; /* XXX: what should this be? */
                                objbuf = objtmp;
                        } else {
@@ -509,7 +516,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
        return do_name_ex(send_bio_chars, out, nm, indent, flags);
 }
 
-
+#ifndef OPENSSL_NO_FP_API
 int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
 {
        if(flags == XN_FLAG_COMPAT)
@@ -524,17 +531,19 @@ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long fla
                }
        return do_name_ex(send_fp_chars, fp, nm, indent, flags);
 }
+#endif
 
 int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
 {
        return do_print_ex(send_bio_chars, out, flags, str);
 }
 
-
+#ifndef OPENSSL_NO_FP_API
 int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
 {
        return do_print_ex(send_fp_chars, fp, flags, str);
 }
+#endif
 
 /* Utility function: convert any string type to UTF8, returns number of bytes
  * in output string or a negative error code