PR: 2711
[openssl.git] / crypto / asn1 / asn_mime.c
index 91488172108b8db2b528089657deb206f0380285..dc2a35d0c8cdb38f5c1301a74551ed653ce7b921 100644 (file)
@@ -276,7 +276,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
 /* SMIME sender */
 
 int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
 /* SMIME sender */
 
 int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
-                               int ctype_nid,
+                               int ctype_nid, int econt_nid,
                                STACK_OF(X509_ALGOR) *mdalgs,
                                const ASN1_ITEM *it)
 {
                                STACK_OF(X509_ALGOR) *mdalgs,
                                const ASN1_ITEM *it)
 {
@@ -340,7 +340,9 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                msg_type = "enveloped-data";
        else if (ctype_nid == NID_pkcs7_signed)
                {
                msg_type = "enveloped-data";
        else if (ctype_nid == NID_pkcs7_signed)
                {
-               if (sk_X509_ALGOR_num(mdalgs) >= 0)
+               if (econt_nid == NID_id_smime_ct_receipt)
+                       msg_type = "signed-receipt";
+               else if (sk_X509_ALGOR_num(mdalgs) >= 0)
                        msg_type = "signed-data";
                else
                        msg_type = "certs-only";
                        msg_type = "signed-data";
                else
                        msg_type = "certs-only";
@@ -423,7 +425,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
  * pointed to by "bcont". In opaque this is set to NULL
  */
 
  * pointed to by "bcont". In opaque this is set to NULL
  */
 
-ASN1_VALUE *SMIME_read_asn1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
+ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
 {
        BIO *asnin;
        STACK_OF(MIME_HEADER) *headers = NULL;
 {
        BIO *asnin;
        STACK_OF(MIME_HEADER) *headers = NULL;
@@ -590,6 +592,8 @@ int SMIME_text(BIO *in, BIO *out)
        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
        while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
                                                BIO_write(out, iobuf, len);
        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
        while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
                                                BIO_write(out, iobuf, len);
+       if (len < 0)
+               return 0;
        return 1;
 }
 
        return 1;
 }
 
@@ -797,7 +801,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
        if(name) {
                if(!(tmpname = BUF_strdup(name))) return NULL;
                for(p = tmpname ; *p; p++) {
        if(name) {
                if(!(tmpname = BUF_strdup(name))) return NULL;
                for(p = tmpname ; *p; p++) {
-                       c = *p;
+                       c = (unsigned char)*p;
                        if(isupper(c)) {
                                c = tolower(c);
                                *p = c;
                        if(isupper(c)) {
                                c = tolower(c);
                                *p = c;
@@ -807,7 +811,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
        if(value) {
                if(!(tmpval = BUF_strdup(value))) return NULL;
                for(p = tmpval ; *p; p++) {
        if(value) {
                if(!(tmpval = BUF_strdup(value))) return NULL;
                for(p = tmpval ; *p; p++) {
-                       c = *p;
+                       c = (unsigned char)*p;
                        if(isupper(c)) {
                                c = tolower(c);
                                *p = c;
                        if(isupper(c)) {
                                c = tolower(c);
                                *p = c;
@@ -831,7 +835,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
                tmpname = BUF_strdup(name);
                if(!tmpname) return 0;
                for(p = tmpname ; *p; p++) {
                tmpname = BUF_strdup(name);
                if(!tmpname) return 0;
                for(p = tmpname ; *p; p++) {
-                       c = *p;
+                       c = (unsigned char)*p;
                        if(isupper(c)) {
                                c = tolower(c);
                                *p = c;
                        if(isupper(c)) {
                                c = tolower(c);
                                *p = c;
@@ -854,6 +858,10 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
 static int mime_hdr_cmp(const MIME_HEADER * const *a,
                        const MIME_HEADER * const *b)
 {
 static int mime_hdr_cmp(const MIME_HEADER * const *a,
                        const MIME_HEADER * const *b)
 {
+       if ((*a)->name == NULL || (*b)->name == NULL)
+               return (*a)->name - (*b)->name < 0 ? -1 :
+                       (*a)->name - (*b)->name > 0 ? 1 : 0;
+
        return(strcmp((*a)->name, (*b)->name));
 }
 
        return(strcmp((*a)->name, (*b)->name));
 }