merge default into my branch roker-linux
authorRoker <roker@pep-project.org>
Mon, 11 Jul 2016 18:58:35 +0200
branchroker-linux
changeset 8563061adc7e3c6
parent 837 bdff704cd921
parent 855 27364c55fbaa
child 859 a3e8f082fc8a
merge default into my branch
     1.1 --- a/.hgignore	Sun Jul 10 13:57:27 2016 +0200
     1.2 +++ b/.hgignore	Mon Jul 11 18:58:35 2016 +0200
     1.3 @@ -36,3 +36,4 @@
     1.4  *.skeleton
     1.5  .skeletons
     1.6  .statemachines
     1.7 +Makefile.protocols
     2.1 --- a/src/identity_list.c	Sun Jul 10 13:57:27 2016 +0200
     2.2 +++ b/src/identity_list.c	Mon Jul 11 18:58:35 2016 +0200
     2.3 @@ -21,6 +21,8 @@
     2.4  DYNAMIC_API identity_list *identity_list_dup(const identity_list *src)
     2.5  {
     2.6      assert(src);
     2.7 +    if (src == NULL)
     2.8 +        return NULL;
     2.9  
    2.10      pEp_identity *_ident = identity_dup(src->ident);
    2.11      if (_ident == NULL)
    2.12 @@ -53,7 +55,9 @@
    2.13  DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
    2.14  {
    2.15      assert(ident);
    2.16 -
    2.17 +    if (ident == NULL)
    2.18 +        return NULL;
    2.19 +    
    2.20      if (id_list == NULL)
    2.21          return new_identity_list(ident);
    2.22  
     3.1 --- a/src/message_api.c	Sun Jul 10 13:57:27 2016 +0200
     3.2 +++ b/src/message_api.c	Mon Jul 11 18:58:35 2016 +0200
     3.3 @@ -33,11 +33,17 @@
     3.4      return bl && string_equality(bl->mime_type, mt);
     3.5  }
     3.6  
     3.7 +//
     3.8 +// This function presumes the file ending is a proper substring of the
     3.9 +// filename (i.e. if bl->filename is "a.pgp" and fe is ".pgp", it will
    3.10 +// return true, but if bl->filename is ".pgp" and fe is ".pgp", it will
    3.11 +// return false. This is desired behaviour.
    3.12 +//
    3.13  static bool is_fileending(const bloblist_t *bl, const char *fe)
    3.14  {
    3.15      assert(fe);
    3.16 -
    3.17 -    if (bl == NULL || bl->filename == NULL)
    3.18 +    
    3.19 +    if (bl == NULL || bl->filename == NULL || fe == NULL)
    3.20          return false;
    3.21  
    3.22      assert(bl && bl->filename);
    3.23 @@ -81,6 +87,9 @@
    3.24      assert(shortmsg);
    3.25      assert(strcmp(shortmsg, "pEp") != 0);
    3.26  
    3.27 +    if (!shortmsg || strcmp(shortmsg, "pEp") == 0)
    3.28 +        return longmsg;
    3.29 +        
    3.30      if (longmsg == NULL)
    3.31          longmsg = "";
    3.32  
    3.33 @@ -97,7 +106,7 @@
    3.34      return ptext;
    3.35  }
    3.36  
    3.37 -static int seperate_short_and_long(const char *src, char **shortmsg, char **longmsg)
    3.38 +static int separate_short_and_long(const char *src, char **shortmsg, char **longmsg)
    3.39  {
    3.40      char *_shortmsg = NULL;
    3.41      char *_longmsg = NULL;
    3.42 @@ -105,6 +114,9 @@
    3.43      assert(src);
    3.44      assert(shortmsg);
    3.45      assert(longmsg);
    3.46 +    
    3.47 +    if (src == NULL || shortmsg == NULL || longmsg == NULL)
    3.48 +        return -1;
    3.49  
    3.50      *shortmsg = NULL;
    3.51      *longmsg = NULL;
    3.52 @@ -169,6 +181,9 @@
    3.53      assert(dst);
    3.54      assert(src);
    3.55  
    3.56 +    if(!(dst && src))
    3.57 +        return PEP_ILLEGAL_VALUE;
    3.58 +
    3.59      free_timestamp(dst->sent);
    3.60      dst->sent = NULL;
    3.61      if (src->sent) {
    3.62 @@ -275,6 +290,8 @@
    3.63      message * msg = NULL;
    3.64  
    3.65      assert(src);
    3.66 +    if (src == NULL)
    3.67 +        return NULL;
    3.68  
    3.69      msg = calloc(1, sizeof(message));
    3.70      assert(msg);
    3.71 @@ -343,6 +360,9 @@
    3.72      _src->enc_format = PEP_enc_none;
    3.73      status = mime_encode_message(_src, true, &mimetext);
    3.74      assert(status == PEP_STATUS_OK);
    3.75 +    if (status != PEP_STATUS_OK)
    3.76 +        goto pep_error;
    3.77 +    
    3.78      if (free_ptext){
    3.79          free(ptext);
    3.80          free_ptext=0;
    3.81 @@ -685,9 +705,9 @@
    3.82  
    3.83      assert(blob);
    3.84  
    3.85 -    if (blob->filename == NULL)
    3.86 +    if (blob == NULL || blob->filename == NULL)
    3.87          return false;
    3.88 -
    3.89 +    
    3.90      ext = strrchr(blob->filename, '.');
    3.91      if (ext == NULL)
    3.92          return false;
    3.93 @@ -709,6 +729,8 @@
    3.94  {
    3.95      assert(blob);
    3.96      assert(blob->filename);
    3.97 +    if (blob == NULL || blob->filename == NULL)
    3.98 +        return false;
    3.99  
   3.100      if (strncmp(blob->filename, "PGPexch.htm.", 12) == 0) {
   3.101          if (strcmp(blob->filename + 11, ".pgp") == 0 ||
   3.102 @@ -724,7 +746,9 @@
   3.103      char *ext;
   3.104  
   3.105      assert(filename);
   3.106 -
   3.107 +    if (filename == NULL)
   3.108 +        return NULL;
   3.109 +    
   3.110      ext = strrchr(filename, '.');
   3.111      if (ext == NULL)
   3.112          return NULL;
   3.113 @@ -767,6 +791,9 @@
   3.114  
   3.115      assert(session);
   3.116      assert(fpr);
   3.117 +    
   3.118 +    if (session == NULL || fpr == NULL)
   3.119 +        return PEP_rating_undefined;
   3.120  
   3.121      PEP_STATUS status = get_key_rating(session, fpr, &comm_type);
   3.122      if (status != PEP_STATUS_OK)
   3.123 @@ -901,6 +928,9 @@
   3.124  {
   3.125      assert(session);
   3.126      assert(msg);
   3.127 +    
   3.128 +    if (session == NULL || msg == NULL)
   3.129 +        return false;
   3.130  
   3.131      bool remove = false;
   3.132  
   3.133 @@ -944,7 +974,7 @@
   3.134  {
   3.135      assert(session);
   3.136      assert(msg);
   3.137 -
   3.138 +    
   3.139      if (msg->dir == PEP_dir_incoming)
   3.140          return;
   3.141  
   3.142 @@ -975,7 +1005,7 @@
   3.143  PEP_cryptotech determine_encryption_format(message *msg)
   3.144  {
   3.145      assert(msg);
   3.146 -
   3.147 +    
   3.148      if (is_PGP_message_text(msg->longmsg)) {
   3.149          msg->enc_format = PEP_enc_pieces;
   3.150          return PEP_crypt_OpenPGP;
   3.151 @@ -1166,6 +1196,8 @@
   3.152      if (msg && msg->shortmsg == NULL) {
   3.153          msg->shortmsg = strdup("pEp");
   3.154          assert(msg->shortmsg);
   3.155 +        if (msg->shortmsg == NULL)
   3.156 +            goto enomem;
   3.157      }
   3.158  
   3.159      if (msg)
   3.160 @@ -1325,6 +1357,9 @@
   3.161                          attctext = _s->value;
   3.162                          attcsize = _s->size;
   3.163  
   3.164 +                        free(ptext);
   3.165 +                        ptext = NULL;
   3.166 +
   3.167                          status = decrypt_and_verify(session, attctext, attcsize,
   3.168                                  &ptext, &psize, &_keylist);
   3.169                          free_stringlist(_keylist);
   3.170 @@ -1400,7 +1435,7 @@
   3.171                      char * shortmsg;
   3.172                      char * longmsg;
   3.173  
   3.174 -                    int r = seperate_short_and_long(msg->longmsg, &shortmsg,
   3.175 +                    int r = separate_short_and_long(msg->longmsg, &shortmsg,
   3.176                              &longmsg);
   3.177                      if (r == -1)
   3.178                          goto enomem;
     4.1 --- a/src/pgp_gpg.c	Sun Jul 10 13:57:27 2016 +0200
     4.2 +++ b/src/pgp_gpg.c	Mon Jul 11 18:58:35 2016 +0200
     4.3 @@ -29,9 +29,17 @@
     4.4          int length = stringlist_length(keys);
     4.5          unsigned int n = (1 << length) - 1;
     4.6  
     4.7 +        // make sure we 1) have the same number of keys and values
     4.8 +        // and 2) we don't have more key/value pairs than
     4.9 +        // the size of the bitfield used to hold the indices
    4.10 +        // of key/value pairs matching keys in the config file.
    4.11          assert(length <= sizeof(unsigned int) * CHAR_BIT);
    4.12          assert(length == stringlist_length(values));
    4.13 -
    4.14 +        if (!(length == stringlist_length(values) &&
    4.15 +              length <= sizeof(unsigned int) * CHAR_BIT)) {
    4.16 +            return false;
    4.17 +        }
    4.18 +        
    4.19          do {
    4.20              char * s;
    4.21  
     5.1 --- a/src/platform_unix.c	Sun Jul 10 13:57:27 2016 +0200
     5.2 +++ b/src/platform_unix.c	Mon Jul 11 18:58:35 2016 +0200
     5.3 @@ -52,7 +52,17 @@
     5.4  
     5.5  long int random(void)
     5.6  {
     5.7 -    static unsigned short xsubi[3] = {'p', 'E', 'p'};
     5.8 +    static bool seeded = false;
     5.9 +    static unsigned short xsubi[3];
    5.10 +    if(!seeded)
    5.11 +    {
    5.12 +        const long long t = (long long)time(NULL);
    5.13 +        xsubi[0] = (unsigned short)t;
    5.14 +        xsubi[1] = (unsigned short)(t>>16);
    5.15 +        xsubi[2] = (unsigned short)(t>>32);
    5.16 +        seeded = true;
    5.17 +    }
    5.18 +
    5.19      return nrand48(xsubi);
    5.20  }
    5.21  
     6.1 --- a/src/stringlist.c	Sun Jul 10 13:57:27 2016 +0200
     6.2 +++ b/src/stringlist.c	Mon Jul 11 18:58:35 2016 +0200
     6.3 @@ -19,8 +19,9 @@
     6.4              free(result);
     6.5              return NULL;
     6.6          }
     6.7 -        result->next = NULL; // needed for one-element lists
     6.8      }
     6.9 +    
    6.10 +    result->next = NULL; // needed for one-element lists
    6.11  
    6.12      return result;
    6.13  }
    6.14 @@ -53,26 +54,32 @@
    6.15      )
    6.16  {  
    6.17      assert(value);
    6.18 +    if (value == NULL)
    6.19 +        return NULL;
    6.20  
    6.21 +    // empty list (no nodes)
    6.22      if (stringlist == NULL)
    6.23          return new_stringlist(value);
    6.24  
    6.25 +    // empty list (one node, no value)
    6.26 +    if (stringlist->value == NULL) {
    6.27 +        if (stringlist->next) 
    6.28 +            return NULL; // invalid list
    6.29 +            
    6.30 +        stringlist->value = strdup(value);
    6.31 +        assert(stringlist->value);
    6.32 +        
    6.33 +        if (stringlist->value == NULL)
    6.34 +            return NULL;
    6.35 +        
    6.36 +        return stringlist;
    6.37 +    }
    6.38 +    
    6.39      stringlist_t* list_curr = stringlist;
    6.40 -    
    6.41 +
    6.42      while (list_curr->next)
    6.43          list_curr = list_curr->next;
    6.44 - 
    6.45 -    // if list end exists without value,
    6.46 -    // we fill it in here instead of adding
    6.47 -    // a new node.
    6.48 -    if (list_curr->value == NULL) {
    6.49 -        list_curr->value = strdup(value);
    6.50 -        assert(list_curr->value);
    6.51 -        if (list_curr->value == NULL)
    6.52 -            return NULL;
    6.53 -        return list_curr;
    6.54 -    }
    6.55 -    
    6.56 +     
    6.57      list_curr->next = new_stringlist(value);
    6.58  
    6.59      assert(list_curr->next);
    6.60 @@ -91,6 +98,7 @@
    6.61      if (stringlist == NULL)
    6.62          return NULL;
    6.63  
    6.64 +    // Second list is empty
    6.65      if (second == NULL || second->value == NULL)
    6.66          return stringlist;
    6.67  
     7.1 --- a/src/stringpair.c	Sun Jul 10 13:57:27 2016 +0200
     7.2 +++ b/src/stringpair.c	Mon Jul 11 18:58:35 2016 +0200
     7.3 @@ -47,6 +47,9 @@
     7.4  DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src)
     7.5  {
     7.6      assert(src);
     7.7 +    if (src == NULL)
     7.8 +        return NULL;
     7.9 +    
    7.10      return new_stringpair(src->key, src->value);
    7.11  }
    7.12  
    7.13 @@ -98,25 +101,29 @@
    7.14  {
    7.15      assert(value);
    7.16  
    7.17 +    // empty list (no nodes)
    7.18      if (stringpair_list == NULL)
    7.19          return new_stringpair_list(value);
    7.20  
    7.21 +    // empty list (one node, no value)
    7.22 +    if (stringpair_list->value == NULL) {
    7.23 +        if (stringpair_list->next)
    7.24 +            return NULL; // invalid list
    7.25 +            
    7.26 +        stringpair_list->value = value;
    7.27 +        assert(stringpair_list->value);
    7.28 +        
    7.29 +        if (stringpair_list->value == NULL)
    7.30 +            return NULL;
    7.31 +        
    7.32 +        return stringpair_list;
    7.33 +    }
    7.34 +    
    7.35      stringpair_list_t* list_curr = stringpair_list;
    7.36      
    7.37      while (list_curr->next)
    7.38          list_curr = list_curr->next;
    7.39 - 
    7.40 -    // if list end exists without value,
    7.41 -    // we fill it in here instead of adding
    7.42 -    // a new node.
    7.43 -    if (list_curr->value == NULL) {
    7.44 -        list_curr->value = value; // ownership goes to us
    7.45 -        assert(list_curr->value);
    7.46 -        if (list_curr->value == NULL)
    7.47 -            return NULL;
    7.48 -        return list_curr;
    7.49 -    }
    7.50 -    
    7.51 +     
    7.52      list_curr->next = new_stringpair_list(value);
    7.53  
    7.54      assert(list_curr->next);
    7.55 @@ -136,6 +143,7 @@
    7.56      if (stringpair_list == NULL)
    7.57          return NULL;
    7.58  
    7.59 +    // second list is empty
    7.60      if (second == NULL || second->value == NULL)
    7.61          return stringpair_list;
    7.62  
     8.1 --- a/sync/gen_actions_skeleton.ysl2	Sun Jul 10 13:57:27 2016 +0200
     8.2 +++ b/sync/gen_actions_skeleton.ysl2	Mon Jul 11 18:58:35 2016 +0200
     8.3 @@ -32,6 +32,7 @@
     8.4                  with "action", ".",
     8.5                  with "fsm", "$name",
     8.6                  with "filename", "$filename";
     8.7 +        |
     8.8      }
     8.9  
    8.10      function "action" {
    8.11 @@ -40,11 +41,15 @@
    8.12          param "filename", "'###'";
    8.13          choose {
    8.14              when "substring($action/@name, 1, 4) = 'send'"
    8.15 -                call "send_action" with "action", "$action",
    8.16 -                     with "fsm", "$fsm", with "filename", "$filename";
    8.17 +                call "send_action"
    8.18 +                    with "action", "$action",
    8.19 +                    with "fsm", "$fsm",
    8.20 +                    with "filename", "$filename";
    8.21              otherwise
    8.22 -                call "other_action" with "action", "$action",
    8.23 -                     with "fsm", "$fsm", with "filename", "$filename";
    8.24 +                call "other_action"
    8.25 +                    with "action", "$action",
    8.26 +                    with "fsm", "$fsm",
    8.27 +                    with "filename", "$filename";
    8.28          }
    8.29      }
    8.30  
    8.31 @@ -168,15 +173,17 @@
    8.32                  goto error;
    8.33              if (Identity_from_Struct(me, &msg->me) == NULL)
    8.34                  goto enomem;
    8.35 -            if "parm or $name='OwnKeys'" |
    8.36 -            if "parm/partner"   |> if (Identity_from_Struct(partner, &msg->partner) == NULL)
    8.37 -            if "parm/partner"   |>> goto enomem;
    8.38 -            if "$name='OwnKeys'"|> stringlist_t *sl;
    8.39 -            if "$name='OwnKeys'"|> status = own_key_retrieve(session, &sl);
    8.40 -            if "$name='OwnKeys'"|> if (status != PEP_STATUS_OK)
    8.41 -            if "$name='OwnKeys'"|>> goto error;
    8.42 -            if "$name='OwnKeys'"|> if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
    8.43 -            if "$name='OwnKeys'"|>> goto enomem;
    8.44 +        ||
    8.45 +        if "parm or $name='OwnKeys'" |
    8.46 +        if "parm/partner"   |> if (Identity_from_Struct(partner, &msg->partner) == NULL)
    8.47 +        if "parm/partner"   |>> goto enomem;
    8.48 +        if "$name='OwnKeys'"|> stringlist_t *sl;
    8.49 +        if "$name='OwnKeys'"|> status = own_key_retrieve(session, &sl);
    8.50 +        if "$name='OwnKeys'"|> if (status != PEP_STATUS_OK)
    8.51 +        if "$name='OwnKeys'"|>> goto error;
    8.52 +        if "$name='OwnKeys'"|> if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
    8.53 +        if "$name='OwnKeys'"|>> goto enomem;
    8.54 +        ||
    8.55  
    8.56              if (asn_check_constraints(&asn_DEF_«$name», msg, NULL, NULL)) {
    8.57                  status = PEP_CONTRAINTS_VIOLATED;
     9.1 --- a/test/stringlist_test.cc	Sun Jul 10 13:57:27 2016 +0200
     9.2 +++ b/test/stringlist_test.cc	Mon Jul 11 18:58:35 2016 +0200
     9.3 @@ -72,32 +72,7 @@
     9.4          assert((p == NULL) == (p_dst == NULL));
     9.5      }
     9.6      assert(p_dst == NULL);
     9.7 -    
     9.8 -    cout << "\nAdd to 4-element stringlist with tail with no value…\n";
     9.9 -    // get tail
    9.10 -    p = src;
    9.11 -    while (p->next)
    9.12 -        p = p->next;
    9.13 -    
    9.14 -    if (p->value)
    9.15 -        free(p->value);
    9.16 -    p->value = NULL;
    9.17 -    
    9.18 -    strarr[3] = str0;
    9.19 -    stringlist_add(src, str0);
    9.20 -    
    9.21 -    cout << "checking contents\n";
    9.22 -    p = src;
    9.23 -    i = 0;
    9.24 -    while (p) {
    9.25 -        assert(p->value);
    9.26 -        assert(strcmp(p->value, strarr[i++]) == 0);
    9.27 -        assert(p->value != *(strarr + i)); // ensure this is a copy
    9.28 -        cout << p->value;
    9.29 -        p = p->next;
    9.30 -    }
    9.31 -    assert(p == NULL); // list ends properly
    9.32 -    
    9.33 +        
    9.34      cout << "freeing stringlists…\n\n";
    9.35      free_stringlist(src);
    9.36      free_stringlist(dst);
    9.37 @@ -113,7 +88,7 @@
    9.38      assert(dst->next == NULL);
    9.39      cout << "one-element stringlist duped, next element is NULL\n";
    9.40      
    9.41 -    cout << "\nAdd to one-element stringlist with no value…\n";
    9.42 +    cout << "\nAdd to empty stringlist (node exists, but no value…)\n";
    9.43      if (src->value)
    9.44          free(src->value);
    9.45      src->value = NULL;