After discussion with Patrick B., we'll return NULL on if decrypt_message doesn't return anything AND the status isn't PEP_UNENCRYPTED or PEP_VERIFIED, not a message. If the semantics change for this case, the code change is an easy fix.
authorKrista Bennett <krista@pep-project.org>
Tue, 09 May 2017 18:19:55 +0200
changeset 1773362524f3e270
parent 1772 4a6cee288e58
child 1774 de28667b0495
After discussion with Patrick B., we'll return NULL on if decrypt_message doesn't return anything AND the status isn't PEP_UNENCRYPTED or PEP_VERIFIED, not a message. If the semantics change for this case, the code change is an easy fix.
src/message_api.c
     1.1 --- a/src/message_api.c	Tue May 09 15:50:21 2017 +0200
     1.2 +++ b/src/message_api.c	Tue May 09 18:19:55 2017 +0200
     1.3 @@ -2494,7 +2494,6 @@
     1.4      PEP_STATUS status = PEP_STATUS_OK;
     1.5      message* tmp_msg = NULL;
     1.6      message* dec_msg = NULL;
     1.7 -    bool dec_empty = true;
     1.8  
     1.9      status = mime_decode_message(mimetext, size, &tmp_msg);
    1.10      if (status != PEP_STATUS_OK)
    1.11 @@ -2507,11 +2506,8 @@
    1.12                                                  rating,
    1.13                                                  flags);
    1.14                                                  
    1.15 -
    1.16 -    dec_empty = (dec_msg == NULL);
    1.17 -
    1.18 -    if (dec_empty) {
    1.19 -        dec_msg = tmp_msg;
    1.20 +    if (!dec_msg && (decrypt_status == PEP_UNENCRYPTED || decrypt_status == PEP_VERIFIED)) {
    1.21 +        dec_msg = message_dup(tmp_msg);
    1.22      }
    1.23          
    1.24      // This is for when errors are seriously fatal, not just decryption probs
    1.25 @@ -2522,8 +2518,6 @@
    1.26          GOTO(pep_error);
    1.27      }
    1.28  
    1.29 -    assert(dec_msg);
    1.30 -    
    1.31      if (!dec_msg) {
    1.32          status = PEP_UNKNOWN_ERROR;
    1.33          GOTO(pep_error);
    1.34 @@ -2534,15 +2528,13 @@
    1.35      if (status == PEP_STATUS_OK)
    1.36      {
    1.37          free(tmp_msg);
    1.38 -        if (!dec_empty)
    1.39 -            free(dec_msg);
    1.40 +        free(dec_msg);
    1.41          return ERROR(decrypt_status);
    1.42      }
    1.43      
    1.44  pep_error:
    1.45      free_message(tmp_msg);
    1.46 -    if (!dec_empty)
    1.47 -        free_message(dec_msg);
    1.48 +    free_message(dec_msg);
    1.49  
    1.50      return ERROR(status);
    1.51  }