adding safeguards
authorVolker Birk <vb@pep.foundation>
Wed, 14 Mar 2018 10:03:20 +0100
changeset 2573eaa8081a98cd
parent 2572 9aaa4c236d08
child 2574 f2e0646c4b0d
adding safeguards
src/mime.c
     1.1 --- a/src/mime.c	Tue Mar 13 11:36:41 2018 +0100
     1.2 +++ b/src/mime.c	Wed Mar 14 10:03:20 2018 +0100
     1.3 @@ -303,6 +303,7 @@
     1.4                    ? mailmime_encode_subject_header("utf-8", ident->username, 0) 
     1.5                    : strdup("");
     1.6                    
     1.7 +    assert(_username);
     1.8      if (_username == NULL)
     1.9          goto enomem;
    1.10  
    1.11 @@ -468,6 +469,7 @@
    1.12  
    1.13      if (msg->id) {
    1.14          char *_msgid = strdup(msg->id);
    1.15 +        assert(_msgid);
    1.16          if (_msgid == NULL)
    1.17              goto enomem;
    1.18  
    1.19 @@ -520,10 +522,13 @@
    1.20      }
    1.21  
    1.22      char* _subject = NULL;
    1.23 -    if (!must_field_value_be_encoded(subject))
    1.24 +    if (!must_field_value_be_encoded(subject)) {
    1.25          _subject = strdup(subject);
    1.26 -    else    
    1.27 +        assert(_subject);
    1.28 +    }
    1.29 +    else {
    1.30          _subject = mailmime_encode_subject_header("utf-8", subject, 1);
    1.31 +    }
    1.32      if (_subject == NULL)
    1.33          goto enomem;
    1.34  
    1.35 @@ -614,10 +619,13 @@
    1.36  
    1.37      if (msg->comments) {
    1.38          char *comments = NULL;
    1.39 -        if (!must_field_value_be_encoded(msg->comments))
    1.40 +        if (!must_field_value_be_encoded(msg->comments)) {
    1.41              comments = strdup(msg->comments);
    1.42 -        else 
    1.43 +            assert(comments);
    1.44 +        }
    1.45 +        else  {
    1.46              comments = mailmime_encode_subject_header("utf-8", msg->comments, 0);
    1.47 +        }
    1.48          if (comments == NULL)
    1.49              goto enomem;
    1.50  
    1.51 @@ -1481,6 +1489,9 @@
    1.52          else if (_is_multipart(content, "encrypted")) {
    1.53              if (msg->longmsg == NULL)
    1.54                  msg->longmsg = strdup("");
    1.55 +            assert(msg->longmsg);
    1.56 +            if (!msg->longmsg)
    1.57 +                return PEP_OUT_OF_MEMORY;
    1.58  
    1.59              clist *partlist = mime->mm_data.mm_multipart.mm_mp_list;
    1.60              if (partlist == NULL)