fix #39 #101: fixed multiple asserts without ifs and spell-checked the function name (only called internally to file)
authorKrista Grothoff <krista@pep-project.org>
Tue, 12 Jul 2016 19:18:04 +0200
changeset 8532a7d4445fca0
parent 852 d47584b9944e
child 854 0d068c87fa66
fix #39 #101: fixed multiple asserts without ifs and spell-checked the function name (only called internally to file)
src/message_api.c
     1.1 --- a/src/message_api.c	Tue Jul 12 19:11:38 2016 +0200
     1.2 +++ b/src/message_api.c	Tue Jul 12 19:18:04 2016 +0200
     1.3 @@ -36,8 +36,8 @@
     1.4  static bool is_fileending(const bloblist_t *bl, const char *fe)
     1.5  {
     1.6      assert(fe);
     1.7 -
     1.8 -    if (bl == NULL || bl->filename == NULL)
     1.9 +    
    1.10 +    if (bl == NULL || bl->filename == NULL || fe == NULL)
    1.11          return false;
    1.12  
    1.13      assert(bl && bl->filename);
    1.14 @@ -80,7 +80,10 @@
    1.15  
    1.16      assert(shortmsg);
    1.17      assert(strcmp(shortmsg, "pEp") != 0);
    1.18 -
    1.19 +    // Will crash without assert if shortmsg == NULL in strlen
    1.20 +    if (shortmsg == NULL)
    1.21 +        shortmsg = strdup(""); // Should this be "pEp", as above?
    1.22 +        
    1.23      if (longmsg == NULL)
    1.24          longmsg = "";
    1.25  
    1.26 @@ -97,7 +100,7 @@
    1.27      return ptext;
    1.28  }
    1.29  
    1.30 -static int seperate_short_and_long(const char *src, char **shortmsg, char **longmsg)
    1.31 +static int separate_short_and_long(const char *src, char **shortmsg, char **longmsg)
    1.32  {
    1.33      char *_shortmsg = NULL;
    1.34      char *_longmsg = NULL;
    1.35 @@ -105,6 +108,9 @@
    1.36      assert(src);
    1.37      assert(shortmsg);
    1.38      assert(longmsg);
    1.39 +    
    1.40 +    if (src == NULL || shortmsg == NULL || longmsg == NULL)
    1.41 +        return -1;
    1.42  
    1.43      *shortmsg = NULL;
    1.44      *longmsg = NULL;
    1.45 @@ -278,6 +284,8 @@
    1.46      message * msg = NULL;
    1.47  
    1.48      assert(src);
    1.49 +    if (src == NULL)
    1.50 +        return NULL;
    1.51  
    1.52      msg = calloc(1, sizeof(message));
    1.53      assert(msg);
    1.54 @@ -346,6 +354,9 @@
    1.55      _src->enc_format = PEP_enc_none;
    1.56      status = mime_encode_message(_src, true, &mimetext);
    1.57      assert(status == PEP_STATUS_OK);
    1.58 +    if (status != PEP_STATUS_OK)
    1.59 +        goto pep_error;
    1.60 +    
    1.61      if (free_ptext){
    1.62          free(ptext);
    1.63          free_ptext=0;
    1.64 @@ -688,9 +699,9 @@
    1.65  
    1.66      assert(blob);
    1.67  
    1.68 -    if (blob->filename == NULL)
    1.69 +    if (blob == NULL || blob->filename == NULL)
    1.70          return false;
    1.71 -
    1.72 +    
    1.73      ext = strrchr(blob->filename, '.');
    1.74      if (ext == NULL)
    1.75          return false;
    1.76 @@ -712,6 +723,8 @@
    1.77  {
    1.78      assert(blob);
    1.79      assert(blob->filename);
    1.80 +    if (blob == NULL || blob->filename == NULL)
    1.81 +        return false;
    1.82  
    1.83      if (strncmp(blob->filename, "PGPexch.htm.", 12) == 0) {
    1.84          if (strcmp(blob->filename + 11, ".pgp") == 0 ||
    1.85 @@ -727,7 +740,9 @@
    1.86      char *ext;
    1.87  
    1.88      assert(filename);
    1.89 -
    1.90 +    if (filename == NULL)
    1.91 +        return NULL;
    1.92 +    
    1.93      ext = strrchr(filename, '.');
    1.94      if (ext == NULL)
    1.95          return NULL;
    1.96 @@ -770,6 +785,9 @@
    1.97  
    1.98      assert(session);
    1.99      assert(fpr);
   1.100 +    
   1.101 +    if (session == NULL || fpr == NULL)
   1.102 +        return PEP_rating_undefined;
   1.103  
   1.104      PEP_STATUS status = get_key_rating(session, fpr, &comm_type);
   1.105      if (status != PEP_STATUS_OK)
   1.106 @@ -904,6 +922,9 @@
   1.107  {
   1.108      assert(session);
   1.109      assert(msg);
   1.110 +    
   1.111 +    if (session == NULL || msg == NULL)
   1.112 +        return false;
   1.113  
   1.114      bool remove = false;
   1.115  
   1.116 @@ -947,7 +968,7 @@
   1.117  {
   1.118      assert(session);
   1.119      assert(msg);
   1.120 -
   1.121 +    
   1.122      if (msg->dir == PEP_dir_incoming)
   1.123          return;
   1.124  
   1.125 @@ -978,7 +999,7 @@
   1.126  PEP_cryptotech determine_encryption_format(message *msg)
   1.127  {
   1.128      assert(msg);
   1.129 -
   1.130 +    
   1.131      if (is_PGP_message_text(msg->longmsg)) {
   1.132          msg->enc_format = PEP_enc_pieces;
   1.133          return PEP_crypt_OpenPGP;
   1.134 @@ -1169,6 +1190,8 @@
   1.135      if (msg && msg->shortmsg == NULL) {
   1.136          msg->shortmsg = strdup("pEp");
   1.137          assert(msg->shortmsg);
   1.138 +        if (msg->shortmsg == NULL)
   1.139 +            goto enomem;
   1.140      }
   1.141  
   1.142      if (msg)
   1.143 @@ -1406,7 +1429,7 @@
   1.144                      char * shortmsg;
   1.145                      char * longmsg;
   1.146  
   1.147 -                    int r = seperate_short_and_long(msg->longmsg, &shortmsg,
   1.148 +                    int r = separate_short_and_long(msg->longmsg, &shortmsg,
   1.149                              &longmsg);
   1.150                      if (r == -1)
   1.151                          goto enomem;