merge
authorEdouard Tisserant
Tue, 12 May 2015 16:38:37 +0200
changeset 2731017daf29ff4
parent 272 f82971ed62e5
parent 269 7eb06a6984fe
child 275 52e3b83ddb5c
child 276 73d4c99cf054
merge
     1.1 --- a/src/bloblist.c	Tue May 12 16:37:31 2015 +0200
     1.2 +++ b/src/bloblist.c	Tue May 12 16:38:37 2015 +0200
     1.3 @@ -33,6 +33,13 @@
     1.4  
     1.5      assert((blob == NULL && size == 0) || (blob && size));
     1.6  
     1.7 +    void *result = realloc(blob, size + 1);
     1.8 +    if (result == NULL) {
     1.9 +        free_bloblist(bloblist);
    1.10 +        return NULL;
    1.11 +    }
    1.12 +    blob[size] = 0; // safeguard
    1.13 +
    1.14      bloblist->data = blob;
    1.15      bloblist->size = size;
    1.16  
    1.17 @@ -57,9 +64,18 @@
    1.18  
    1.19      assert(src);
    1.20  
    1.21 -    bloblist = new_bloblist(src->data, src->size, src->mime_type, src->filename);
    1.22 +    char *blob2 = malloc(src->size + 1);
    1.23 +    assert(blob2);
    1.24 +    if (blob2 == NULL)
    1.25 +        goto enomem;
    1.26 +
    1.27 +    memcpy(blob2, src->data, src->size);
    1.28 +    blob2[src->size] = 0; // safeguard
    1.29 +
    1.30 +    bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
    1.31      if (bloblist == NULL)
    1.32          goto enomem;
    1.33 +    blob2 = NULL;
    1.34  
    1.35      if (src->next) {
    1.36          bloblist->next = bloblist_dup(src->next);
    1.37 @@ -70,6 +86,7 @@
    1.38      return bloblist;
    1.39  
    1.40  enomem:
    1.41 +    free(blob2);
    1.42      free_bloblist(bloblist);
    1.43      return NULL;
    1.44  }
    1.45 @@ -101,6 +118,13 @@
    1.46  
    1.47          assert((blob == NULL && size == 0) || (blob && size));
    1.48  
    1.49 +        void *result = realloc(blob, size + 1);
    1.50 +        if (result == NULL) {
    1.51 +            free_bloblist(bloblist);
    1.52 +            return NULL;
    1.53 +        }
    1.54 +        blob[size] = 0; // safeguard
    1.55 +
    1.56          bloblist->data = blob;
    1.57          bloblist->size = size;
    1.58  
     2.1 --- a/src/message_api.c	Tue May 12 16:37:31 2015 +0200
     2.2 +++ b/src/message_api.c	Tue May 12 16:38:37 2015 +0200
     2.3 @@ -710,8 +710,10 @@
     2.4          case PEP_DECRYPTED_AND_VERIFIED:
     2.5              return PEP_rating_reliable;
     2.6  
     2.7 +        case PEP_DECRYPT_NO_KEY:
     2.8 +            return PEP_rating_have_no_key;
     2.9 +
    2.10          case PEP_DECRYPT_WRONG_FORMAT:
    2.11 -        case PEP_DECRYPT_NO_KEY:
    2.12          case PEP_CANNOT_DECRYPT_UNKNOWN:
    2.13              return PEP_rating_cannot_decrypt;
    2.14  
    2.15 @@ -801,7 +803,7 @@
    2.16      message *msg = NULL;
    2.17      char *ctext;
    2.18      size_t csize;
    2.19 -    char *ptext;
    2.20 +    char *ptext = NULL;
    2.21      size_t psize;
    2.22      stringlist_t *_keylist = NULL;
    2.23      bool free_src = false;
    2.24 @@ -823,12 +825,16 @@
    2.25      *color = PEP_rating_undefined;
    2.26   
    2.27      switch (src->enc_format) {
    2.28 +        case PEP_enc_none:
    2.29 +            status = PEP_UNENCRYPTED;
    2.30 +            break;
    2.31 +
    2.32          case PEP_enc_PGP_MIME:
    2.33              ctext = src->attachments->next->data;
    2.34 -            csize = strlen(ctext);
    2.35 +            csize = src->attachments->next->size;
    2.36  
    2.37 -            status = cryptotech[crypto].decrypt_and_verify(session,
    2.38 -                    ctext, csize, &ptext, &psize, &_keylist);
    2.39 +            status = cryptotech[crypto].decrypt_and_verify(session, ctext,
    2.40 +                    csize, &ptext, &psize, &_keylist);
    2.41              if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
    2.42                  goto pep_error;
    2.43              decrypt_status = status;
    2.44 @@ -838,8 +844,8 @@
    2.45              ctext = src->longmsg;
    2.46              csize = strlen(ctext);
    2.47  
    2.48 -            status = cryptotech[crypto].decrypt_and_verify(session, ctext, csize,
    2.49 -                    &ptext, &psize, &_keylist);
    2.50 +            status = cryptotech[crypto].decrypt_and_verify(session, ctext,
    2.51 +                    csize, &ptext, &psize, &_keylist);
    2.52              if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
    2.53                  goto pep_error;
    2.54              decrypt_status = status;
    2.55 @@ -872,7 +878,7 @@
    2.56      if (ptext) {
    2.57          switch (src->enc_format) {
    2.58              case PEP_enc_PGP_MIME:
    2.59 -                status = mime_decode_message(ptext, &msg);
    2.60 +                status = mime_decode_message(ptext, psize, &msg);
    2.61                  if (status != PEP_STATUS_OK)
    2.62                      goto pep_error;
    2.63                  break;
    2.64 @@ -983,7 +989,7 @@
    2.65      *dst = msg;
    2.66      *keylist = _keylist;
    2.67  
    2.68 -    return decrypt_status;
    2.69 +    return PEP_STATUS_OK;
    2.70  
    2.71  enomem:
    2.72      status = PEP_OUT_OF_MEMORY;
     3.1 --- a/src/message_api.h	Tue May 12 16:37:31 2015 +0200
     3.2 +++ b/src/message_api.h	Tue May 12 16:38:37 2015 +0200
     3.3 @@ -49,6 +49,7 @@
     3.4  typedef enum _PEP_color {
     3.5      PEP_rating_undefined = 0,
     3.6      PEP_rating_cannot_decrypt,
     3.7 +    PEP_rating_have_no_key,
     3.8      PEP_rating_unencrypted,
     3.9      PEP_rating_unreliable,
    3.10      PEP_rating_reliable,
     4.1 --- a/src/mime.c	Tue May 12 16:37:31 2015 +0200
     4.2 +++ b/src/mime.c	Tue May 12 16:38:37 2015 +0200
     4.3 @@ -1391,6 +1391,7 @@
     4.4  
     4.5  DYNAMIC_API PEP_STATUS mime_decode_message(
     4.6          const char *mimetext,
     4.7 +        size_t size,
     4.8          message **msg
     4.9      )
    4.10  {
    4.11 @@ -1409,7 +1410,7 @@
    4.12      *msg = NULL;
    4.13  
    4.14      index = 0;
    4.15 -    r = mailmime_parse(mimetext, strlen(mimetext), &index, &mime);
    4.16 +    r = mailmime_parse(mimetext, size, &index, &mime);
    4.17      assert(r == 0);
    4.18      assert(mime);
    4.19      if (r) {
     5.1 --- a/src/mime.h	Tue May 12 16:37:31 2015 +0200
     5.2 +++ b/src/mime.h	Tue May 12 16:38:37 2015 +0200
     5.3 @@ -50,6 +50,7 @@
     5.4  //
     5.5  //  parameters:
     5.6  //      mimetext (in)           MIME encoded text to decode
     5.7 +//      size (in)               size of text to decode
     5.8  //      msg (out)               decoded message
     5.9  //
    5.10  //  return value:
    5.11 @@ -67,6 +68,7 @@
    5.12  
    5.13  DYNAMIC_API PEP_STATUS mime_decode_message(
    5.14          const char *mimetext,
    5.15 +        size_t size,
    5.16          message **msg
    5.17      );
    5.18  
     6.1 --- a/test/message_api_test.cc	Tue May 12 16:37:31 2015 +0200
     6.2 +++ b/test/message_api_test.cc	Tue May 12 16:38:37 2015 +0200
     6.3 @@ -68,9 +68,10 @@
     6.4      stringlist_t *keylist4;
     6.5      PEP_color color;
     6.6      PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &color);
     6.7 -    assert(status4 == PEP_DECRYPTED_AND_VERIFIED);
     6.8 +    assert(status4 == PEP_STATUS_OK);
     6.9      assert(msg4);
    6.10      assert(keylist4);
    6.11 +    assert(color);
    6.12  
    6.13      cout << "keys used:";
    6.14      stringlist_t *kl4;